git — beginners guide

Himanshu Pratap
1 min readMar 4, 2022

--

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 himanshupratap@gmail.com
$ 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

--

--