Show Menu
Cheatography

git-pro cheat sheet Cheat Sheet (DRAFT) by

git cheat sheet from git-pro book

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

config­uration

username
git config --global user.name "John Doe"
email
git config --global user.email johndo­e@g­mai­l.com
default editor
git config --global core.e­ditor emacs
check current settings
git config --list
getting help
git help <ve­rb>
git help config
For specific projects, just remove the
--global
option

.gitignore file example

# no .a files
*.a

# but do track lib.a, even though you're ignoring .a files above
!lib.a

# only ignore the TODO file in the current directory, not subdir/TODO
/TODO

# ignore all files in the build/ directory
build/

# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt

# ignore all .pdf files in the doc/ directory
doc/*/.pdf
 

track projects

track existing
git init
 
this should be done inside existing directory
clone project
git clone <ur­l>
clone project in dir
git clone <ur­l> <de­st-­url>
check status
git status
check status (short)
git status -s
track new file or add to staging (before commit)
git add <fi­len­ame>
 
Remember: if you stage a file and then change it again, this will be marked as changed and not staged and will be committed without the latest changes (not yet staged)
commit changes (comment on editor)
git commit
commit changes (comment inline)
git commit -m "­commit messag­e"
commit skipping staging
git commit -am "­mes­sag­e"
remove & delete file
git rm <fi­le>
 
file will be removed from working AND staging area
remove & keep file
git rm --cached <fi­le>
 
file be not tracked but kept in working area
rename­/move file
git mv file.txt newfil­e.txt
git status -s example
MM Rakefile = has been staged as modified and then modified again in the working space (and this edit has not been staged yet).
_M Readme = modified in working space and not staged yet
?? LICENC­E.TXT = not tracked yet
A_ file.txt = added to staging

git rm examples
 git rm log/*.log

git rm *~
 

check differ­ences

working vs staged
git diff
staged vs commit
git diff --staged
check diff external editor
git difftool --tool­-help
use external editor
git difftool