or   Register or Register today to make and share your own cheat sheets! (Why Join?)

Cheatography Login

Join Us!

Not a Cheatographer? Register here!

Social Media

You can login to or register with Cheatography using your Facebook or Twitter account!

Why Join Cheatography?

Make and share cheat sheets!
Join a great community of Cheatographers and add your very own contributions.

Save your favourites!
Quick access to your most loved cheat sheets.

Fewer ads!
Members see no ads on the site.

Coming soon ...
Requests, ratings and more!

Why Join Cheatography?

Make and share cheat sheets!
Join a great community of Cheatographers and add your very own contributions.

Save your favourites!
Quick access to your most loved cheat sheets.

Fewer ads!
Members see no ads on the site.

Coming soon ...
Requests, ratings and more!

Git Cheat Sheet by SamCollett

3 Comments   |   Add a Comment   |   PDF Download   |   Find:

Create Git Repository

From existing direct­ory
cd proje­ct_dir
git init
git add .
From other reposi­tory
git clone exist­ing­_dir new_dir
git clone git:/­/gi­thu­b.c­om/­use­r/r­epo.git
git clone https­://­git­hub.co­m/u­ser­/re­po.git

Git - Local Changes

Changed in working direct­ory
git status
Tracked file changes
git diff
Add changed files
git add file1 file2 file3
Remove file
git rm file
git rm dir/ -r
(recu­rsive under direct­ory)
See files ready for commit
git diff --cached
Commit changes
git commit
git commit -m "My messag­e"
git commit -a -m "My Messag­e"
(tracked files only, auto add)
Change last commit
git commit --amend
Revert changes to file
git checkout -- file
Revert changes (new commit)
git revert HEAD
Return to last committed state
git reset --hard HEAD
 

Git - History

Show all commits
git log
Short Format
git log --pret­ty=­short
Patc­hes
git log -p
Show file commits
git log file
Show directory commits
git log dir/
Stats
git log --stat
Who changed file
git blame file

Git - Merge/Rebase

Merge branch into current
git merge branch
Rebase into branch
git rebase branch
git rebase master branch
Abort rebase
git rebase --abort
Merge tool to solve confli­cts
git mergetool
Conf­licts against base file
git diff --base file
Diff other users changes
git diff --theirs file
Diff your changes
git diff --ours file
After resolving confli­cts
git rebase --continue
 

Git - Remote Update / Publish

List remotes
git remote -v
Show inform­ation
git remote show remote
Add remote
git remote add path/url
Fetch changes
git fetch remote
Fetch + merge
git pull remote branch
Publish local to remote
git push remote branch
Delete remote branch
git push remote :branch
Publish tags
git push --tags

Git - Branching/Tagging

List branches
git branch
Switch to branch
git checkout branch
Create new branch
git branch new
Create branch from existing
git branch new existing
Delete branch
git branch -d branch
Tag current commit
git tag tag-name

Favourited by 39 Members:

CITguy polarnj xcjjzh arnoldobr manoelhc dimitrios CliveWalkden DaveChild akuiraz iknowsbest pmg javovo hariadi zenweasel naesk Wbbourne slovacus maintainweb sebbu fedesilva donnedslug chohdry zeroeth cpettit42 crss1138 kjhughes dttk simspace pedromarban mvotani martinku petraeus mstrbutlertron manjuv.gmit norixxx apurohit wdfelippe ovi_mihai ifdattic

Comments

DaveChild DaveChild, 10:02 28 Nov 11

Sam, that's brilliant! I'm still using SVN, but dabbling in Git, and this is just the thing to help me make the jump. Great cheat sheet!

Ray Noel Ray Noel, 15:19 26 Feb 12

Yes, the content is exactly what I am looking for too. It would be even better for these tired old eyes with <font size=+2pt> lol.

I'm sure that increasing the font size won't cause any problems width-wise; plenty of space in all three columns, even with Letter-sized paper. And there's space aplenty at the bottom of an A4 page so there's be even more on Letter-sized paper.

Great cheat sheet all the same!

mvotani mvotani, 12:06 14 Nov 12

It would be interesting to add commands to resolve merge with binary files, as stated here:
http://stackoverflow.com/questions/278081/resolving-a-git-conflict-with-binary-files

It's pretty simple, but really hard to figure out when you don't have enough experience with Git!
And it's known that Git is not so intuitive when working with binary files...

The commands are:
$ git checkout --theirs -- path/to/conflicted-file.txt - select file coming from merged in branch
$ git checkout --ours -- path/to/conflicted-file.txt - select original file on branch before merge

But great sheet anyway, helps a lot!

Add a Comment

Comment:

Contents

Cheat Sheet for the Git Distri­buted Version Control System. Based on https:­//g­ith­ub.c­om­/Al­exZ­eit­ler­/gi­tch­eat­sheet and http:/­/ww­w.g­it-­tow­er.c­om­/fi­les­/ch­eat­she­et/­Git­_Ch­eat­_Sh­eet­_gr­ey.pdf

Column Content Comments Author Updated
- Git Cheat Sheet SamCollett 5 Jan 12
1 Create Git Repository 0 SamCollett 23 Nov 11
Git - Local Changes 0 SamCollett 5 Jan 12
2 Git - History 0 SamCollett 23 Nov 11
Git - Merge/Rebase 0 SamCollett 23 Nov 11
3 Git - Remote Update / Publish 0 SamCollett 23 Nov 11
Git - Branching/Tagging 0 SamCollett 23 Nov 11