Show Menu
Cheatography

Git Cheat Sheet (DRAFT) by

Some useful Git commands

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

Basic

git checkout <br­anc­h>
switch to <br­anc­h>
git checkout -b <br­anc­h>
create <br­anc­h> and switch to it
git status
show uncommited changes
git add <fi­le>
add <fi­le> changes to next commit
git add .
add all changes to next commit
git commit
commit selected changes
git commit -amend
commit selected changes overwr­itting last commit
git merge <br­anc­h>
merge <br­anc­h> into current branch

Remote

git fetch <re­mot­e>
fetch branches from <re­mot­e>
git pull <re­mot­e>
fetch branches and merge
git push <re­mot­e> <br­anc­h>
upload local <br­anc­h> to <re­mot­e>

Reset

git reset --hard
Undo last commit and delete changes
git reset --soft
Undo last commit keeping changes in working directory
git reset <sh­a>
Reset until commit <sh­a>
git reset HEAD~<­n>
Reset <n> commits

Stash

git stash
stash changes from working directory
git stash apply
apply stashed changes to working directory
git stash pop
apply stashed changes to working directory and remove them from stash
git stash drop
remove stored changes from stash
git stash clear
clear all stashed changes

CherryPick - Rebase

git cherry­-pick <sh­a>
apply <sh­a> commit into current branch
git cherry­-pick <sh­a> --no-c­ommit
apply <sh­a> commit into working directory
git rebase <br­anc­h>
apply current branch commits to <br­anc­h> head
git rebase --inte­ractive <br­anc­h>
apply current branch commits to <br­anc­h> head one by one