Show Menu
Cheatography

ThomasTrainGit Cheat Sheet (DRAFT) by

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

Instal­lation and setup

git config --global user.name "John Doe"
git config --global user.email johndo­e@e­xam­ple.com

Get repository

git clone <ur­l>
use ssh not https
git init
new local repository

Basic workflow

what I have edited
git status
mark for commit (move to green)
git add <fi­le>
commit from staging (green area)
git commit
look at my commit in history
git log
push to server
git push origin <br­anc­h>
download and merge latest server work
git pull origin <br­anc­h>

Resolve conflict

see confli­cting files
git status
abort merge
git merge --abort
accept only my changes
git checkout --ours <fi­le>
accept only incoming changes
git checkout --theirs <fi­le>
mark conflict as resolved
git add <fi­le>
finish merge
git commit
 

Branching

create and switch to branch
git checkout -b <na­me>
list local branches
git branch
switch active branch
git checkout <na­me>
merge branch
git merge <na­me>
delete branch
git branch -D <na­me>

Tag

new tag
git tag <na­me>
list of tags
git tag
remove tag
git tag -d <na­me>

Remove edits

from stage to changes (green to red)
git reset HEAD <fi­le>
remove edits
git checkout <fi­le>

Stash

move edits to stash
git stash
apply topmost stashed edits
git stash apply
clear stash
git stash clear

Tips

get branch to server state
git reset --hard origin­/<b­ran­ch>
load up sources from prev. commit
git checkout HEAD^