git — beginners guide

Git was originally authored by Linus Torvalds for development of the Linux kernel, with other kernel developers contributing to its initial development.

It is an opensource software for tracking changes in any set of files, usually used for collaboratively developing source code during software development.

Some useful git command

  1. Check git version
$ git --version

2. GIT global configuration

$ git config --global user.name "Himanshu Pratap"
$ git config --global user.email
$ git config --list
$ git config --global core.editor "code --wait"

3. Initialize a directory as git repository

$ mkdir git_test
$ cd git_test
$ git init
$ git status

4. Add files to the staging area

$ git add .

5. Commit the changes to git repository

$ git commit -m "first commit"

6. view all git commit

$ git log --oneline
$ git log

7. checkout the file from an older commit

$git checkout <commit> <file>

8. Add online remote git repository

$ git remote add origin <repository url>
$ git push -u origin master

9. Clone an online repository

$ git clone <repository url>

10. Reset to previous commit

$ git reset --hard <SOME-COMMIT> t

11. Overwrite local files with git pull from remote repository

git fetch --all
git reset --hard origin/master

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store