Show Menu
Cheatography

git_cs Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Branching, Merging, and Fetching

git branch [-v] [(--merged | --no-m­erged)]
Lists all the alive branches
git branch <br­anc­h> <re­mot­e>
Creates a new branch
git branch -d <br­anc­h>
Deletes a branch
git checkout <br­anc­h>
Switches to a branch
git checkout -b <br­anc­h>
Creates and switches to a new branch
git merge <br­anc­h>
Merges the checke­d-out branch with the <br­anc­h> one
git fetch [<r­emo­te>­|--all]
Updates the local info about the remote branch data
git push [-u] <re­­mo­t­e> <br­­an­c­h­>[:­<re­mot­e_b­ran­ch>]
Pushed the branch to the remote server
git pull <re­­mo­t­e>
Fetches and pulls a remote branch
git rebase <re­mot­e>
From last common ancestor, applies remote, then local changes
 

Git Status Checks

git status [-s]
Checks the status of local repo
git check --diff
Checks for trailing whites­paces
git diff [--cached]
Shows staged and unstaged changes
git log [-p] [-n] [--grep [--pretty] [-Sfoo]
Shows the repo history

Undoing Things

git commit --amend
Undoes the last commit
git reset HEAD <fi­le>
Unstages the changes to a file or directory
git checkout -- <fi­le>
Undoes the changes to a file or directory

Tagging

git tag [-l]
Lists all tags
git tag -a <ta­g> [-m <ms­g>]
Creates a <ta­g> tag
git push <or­igi­n> [<t­ag> | --tags]
Shares the tag
git checkout -b <br­anc­h> <ta­g>
Tag checkout
 

Terms

Tracking branch
Local branch that has a direct relati­onship to a remote branch
Refspec
Patch

Get latest from Git branch

git fetch origin/<branch>
git rebase origin/<branch>
git merge origin/<branch>

Add file to .gitignore

git rm --cached <file>
echo '<file>' .gitignore
git commit -m "Added <file> to .gitignore"
Removes file from git, keeping them in the hard drive

Tagging Later

git log --pretty=online
git tag -a <tag> <tag> <commit_hash>

Common aliases

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'