Git quick reference



(Target audience: developers who knows SVN/CVS, so it skips some intro about Git)


Command-line client (Windows: )

View command help (options, parameters, … ) :

git help command


git command –help

(command is one of: clone , config, add , commit , push , log , fetch , pull , merge , rebase , checkout , branch , reset , status, blame, diff , apply , revert , update-ref, … )


GUI client


TortoiseGit (& MsysGit):



IDE integration/plugins

Eclipse: EGit plugin, update site –




Collaboration models




Popular: single-man project, small team (< 6 developers) with high trust, SVN evangelists .

Also known as: Blessed-center, Free-for-all, Shared-repo .

Summary: Everybody pull and push changes to One centralized (blessed/shared) repository – “origin” , One branch “master” (exactly the same way with SVN – trunk & HEAD) .

Visualized model/workflow: SharedRepo Model DucQuoc

Common operations:

git init --bare /path/to/repo.git

git clone https://user@host/path/to/repo.git

git status # View the state of the repo
git add LocalFile.txt # Stage a file 'LocalFile.txt'
git commit # Commit a file

git push origin master

git pull --rebase origin master

git rebase --continue LocalFile.txt

git push origin master


Branch upstream

Popular: Small & Medium team (5-40 developers), private/prorietary repo.

Also known asFeature-branchCheckout-rebase

Summary: Everybody create their own branch (for some feature/issue), then commits to it. Later branch will be pushed to remote ‘origin’, then merged (after pull-request).

Visualized model/workflowFeatureBranch GitModel DucQuoc

Common operations:

# switch to new branch 'ducquoc-br' based on master
git checkout -b ducquoc-br master
# modify and add some file
git status
git add DucFile.txt
git commit
# push to remote repo 'origin', branch 'ducquoc-br'
git push -u origin ducquoc-br 
# update some more and push
git push

# pull a branch with rebase option to fetch without merge
git pull --rebase origin ducquoc-br

# reset local master branch to be latest as origin
git checkout origin/master
git branch -D master
git branch master
git checkout master 

# reset local master branch - using reset hard
git update-ref refs/heads/master origin/master
git reset --hard master

# delete a local branch 'ducquoc-br'
git branch -D ducquoc-br
# delete remote branch 'ducquoc-br' on 'origin' (and strip some un-merged commits)
git branch -rd origin/ducquoc-br 
git push origin :ducquoc-br # If you don't use the colon ':' , use --delete option instead


Fork master

Popular: Medium or big size teams, Open Source projects, Online/cloud hosting projects.

Also known asGitHub-flowFork-and-PullUpstream-repo

Summary: Everybody forks the repo (as a clone ‘upstream‘), then modify master branch and push to ‘upstream’. Pull requests are primarily to merge ‘master‘ of ‘upstream‘ to ‘origin’.

Visualized model/workflowForkNPull GitModel DucQuoc

Common operations:

# list the current remote repos
git remote -v
# set a new remote 'upstream'
git remote add upstream https://upstream-repo-URL/repo.git
# fetch the upstream repo - not merge/rebase yet
git fetch upstream
# switch to 'master' branch and merge upstream's master branch
git checkout master
git merge upstream/master
git log HEAD..origin/master


Dictator & lieutenant

Popular: not popular, just in case there are a few ‘newbies/rookies’ who are eager to commit and push code (usually with low quality).

Also known asReviewerAmbassadorBenevolent-Bottleneck

Summary: just a dialect of ‘Branch upstream‘ or ‘Fork master‘ , but instead of pushing to ‘origin‘ , normal devs will push to main devs repo (lieutenants), and from then push to the dictator repo ‘reviewer‘ , then the ‘reviewer’ will decide to merge and push to ‘origin‘.

Visualized model/workflowDictator GitModel DucQuoc

Common operations:

git stash
git stash apply
git stash save "work in progress - login CSRF 2013.08.15 duc"
git stash list
git stash apply stash@{1}
git stash pop #different from apply: will delete the applied stash
git stash drop <HASH>
git stash clear




+ OrCz crash course:

+ Net Tuts+ guide:

+ Vogella’s tutor:

+ Scott Chacon’s ProGit:

+ Command quick reference:

+ Command reference:

+ Online hosts: GitHub, BitBucket, Gitorious, GoogleCode, Assembla,, Unfuddle, GitLab, CloudHost, Deveo, …

(For certain GUI clients, you may visit the official documentation of the client tool for latest updates, since they are not consistent with each other.

For instance, EGit:




FAQ of branch-upstream model

1/ How do I update latest code (origin master) for my local brach (assumed name duc-br ) ?

Use below commands to sync master on a daily basis (update duc-br to your branch name) :


git checkout master && git pull && git checkout duc-br && git merge master


2/ How do I make my master branch exactly the same with latest origin master ?

Use below commands:

git update-ref refs/heads/master origin/master && git reset --hard master 


3/ How do I make my duc-br branch the same with remote branch duc-br (origin)?

Use below commands:

git update-ref refs/heads/duc-br origin/master && git reset --hard duc-br 


4/ How do I save all my non-commit changes to another new branch ( new-br ) ? 

Use below commands (update new-br to your new branch name) :

git stash && git stash branch new-br


5/ How do I revert my code to previous commit (i.e. discard all non-commit changes) ? 

Use below commands:

git reset HEAD^ --hard


6/ How do I revert my code to latest commit of previous pull (i.e. discard all non-commit changes) ? 

Use below commands:

git reset HEAD --hard


7/ What is the different between update/merge of “rebase”, “stash”, “cherry-pick” ? 

Read the friendly manual !

But any GUI client tool should support all of those and just use one is enough for a convention.


Stash (temporarily store the work in progress to local stage or another branch):–cms-22988

Rebase (re-arrange the commits so that history looks better):

Cherry-pick (select a few of commits to merge to the branch):


(to be updated)




A coder, husband and brother...
This entry was posted in Coding, Linux, Skill. Bookmark the permalink.

One Response to Git quick reference

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s