Git Basics Cheatsheet

Git Basics Cheatsheet

A Small Cheatsheet of Git Basics Only

1. Repository Creation

To create a new local repository from start :

$ git init

To clone a existing repository :

$ git clone your_url

2. Repository Observation

Shows new or modified files not yet committed :

$ git status

Shows the changes made to files :

$ git diff

3. Branches

List all local branches :

$ git branch

List all local and remote branches :

$ git branch -av

To merge branch_a into branch_b :

$ git checkout branch_b
$ git merge branch_a

To tag the current commit :

$ git tag <my-tag>

4. Changes

To stage the file ready for commit :

$ git add <file-name>

To stage all changed files ready for commit :

$ git add .

To commit all staged files to versioned history :

$ git commit - m <message>

To commit all tracked files to versioned history :

$ git commit - am <message>

To show full changed history :

$ git log

5. Push, Reset and Status

To push local changes to remote repo :

$ git push

To push all of the tags to the remote repo :

$ git push --tags <repo-name>

To unstage a staged file :

$ git reset <file-name>

To reset everything to last commit :

$ git reset --hard HEAD

To get the current status of the repository :

$ git status

6. Pull

To get latest changes from remote repo

$ git fetch

To get latest changes from remote repo and merge

$ git pull

7. Help

To get help when in doubt

$ git help

Thanks for reading my article on Git Basics Cheatsheet. In this i tried to cover only basics one. Kindly leave your feedback inside comment section below.