Useful Git commands

This post will guide you through usefull Git commands.

1. To install Git

sudo apt-get install git

2. Initialise Git repository.

git init

3. To show the status of Git repository. It show the list of files and created directory where we made our changes

git status

4. To know the latest commits in master repository

git log

5. To know the current working branch

git branch

6. To make a switch on other existing branch

git checkout BRANCH_NAME

7. To create a new branch

git checkout -b BRANCH_NAME

8. To add new file


9. To commit locally with message.

git commit -m Title of patch

10. To generate patch file. Here i = No. of patches you want to generate.

git format-patch BRANCH_NAME~i

11. To generate next version of patch.

git format-patch BRANCH_NAME~i -vn

12. To send email

sudo apt-get install git-email // Installs the git email
git send-email LOCATION_OF_PATCH_FILE --cc=_EMAIL_ID //to send a email

13. To apply a patch


14. To rebase

git rebase -i HEAD~n //Here, n=1,2,..N which tells number of commits you would like to edit
Written on May 18, 2019