Git Commands Quick List

Russell Bateman
February 2019
last update:

(Yes, I do accept suggestions for commands to be added to this summary.)

Description Command
Configuration
Configure author name to be used with commits git config --global user.name "Jack the Ripper"
Configure author e-mail address to be used with commits git config --global user.email [email protected]
Configure to enable color in git messages git config color.ui true
Remove user credential details from repository git config --local credential.helper ""
List all configured remote repository URLs git remote -v
Add a remote server to a local repository git remote add origin URL
commit and push
List changes/status git status
List changes/status short version git status -s
Stage a file for commit git add filepath
Stage all files for commit git add .
Command changes to HEAD with message git commit -m "message"
Push all commits to repository git push
Push commits to named branch of remote repository git origin branch
checkout and pull
Initialize local filesystem subdirectory as repository git init
Clone repository to local filesystem subdirectory git clone URL
Download objects and references from remote master git fetch origin master
Merge another branch into current git merge branch-name
Fetch and merge changes from the remote git pull
View merge conflicts git diff
View conflicts against base git diff −−base filename
Preview changes (before merging) git diff source-branch target-branch
branch
List branches in repository git branch
Switch to a branch git checkout branch-name
Create new branch and switch to it git checkout -b branch-name
Create new branch off of master and switch to it git checkout -b branch-name master
Delete branch from repository git branch -d branch-name
clean
Clean repository to initial stage git clean -x -d -f
Reset local repository and point local master to latest git reset −−hard origin/master
Fetch and merge all changes from remote master to local git pull origin master
Other commands
Tag to mark a significant change, such as a release git tag version commit id
Discover commit ids git log
Push all tags to remote git push −−tags origin
(After messing up), replace changes in local with HEAD git checkout −− filename
Search local for "foo()" git grep "foo()"