Show Menu
Cheatography

Git Cheat Sheet Cheat Sheet by

REMOTE INFORM­ATION

Clone a repository
git clone <re­pos­ito­ry_­url>
Get remote refs and objects
git fetch
Get remote branch (fetch previo­suly)
git checkout <re­mot­e_b­ran­ch_­nam­e>
Get remote changes from branch
git pull
Get remote changes by putting ours on top
git pull --rebase
Same and stashing local changes
git pull -r --auto­stash
Send changes to remote branch
git push origin <lo­cal­_br­anc­h>
Send changes to local branch to another remote branch
git push origin <lo­cal­_br­anc­h>:­<re­mot­e_b­ran­ch>
Force push changes
git push -f origin <lo­cal­_br­anc­h>

BRANCHING

Create branch
git branch <br­anc­h_n­ame>
Remove local branch
git branch -d <br­anc­h_n­ame>
Track remote branch
git branch --set-­ups­tre­am-to origin­/<r­ama­_re­mot­a> <ra­ma_­loc­al>​
Move from branch
git checkout <br­anc­h_n­ame>
Create branch and move to her
git checkout -b <br­anc­h_n­ame>
Remove remote branch
git push origin :<r­emo­te_­nam­e_b­ran­ch>
 

SAVE CHANGES

Add file changes to the stage for commit
git add <fi­len­ame>
Add all changes to the stage
git add -A
Create commit with message
git commit -m "­<me­ssa­ge>­"
Add files to existing commit holding message
git commit --amend --no-edit
No commited changes quick saves in stack
git stash -u
Show all stashes
git stash list
Apply changes from stash
git stash apply
Apply last stash and take out from stack
git stash pop

UNDO CHANGES

Undo file changes out of stage
git checkout <fi­len­ame>
Take out file of stage
git reset <fi­len­ame>
Move from branch and undo all no commited changes
git checkout -f <br­anc­h>
Undo N last commits
git reset --hard HEAD~N
Undo N last commits holding changes in stage
git reset HEAD~N
Undo N last commits holding changes out of stage
git reset --soft HEAD~N
Revert changes N last commits (remote)
git revert HEAD~N
 

STATUS

Show current branch
git branch
Show local and remote tracked branches
git branch -a
List branch inform­ation in verbose mode
git branch -vv
Show branch status
git status
Show file changes
git diff <fi­len­ame>
Show commits history of current branch
git log
Pretty log example
git log --graph --abbr­ev-­commit --decorate --form­at=­for­mat­:'%­C(bold blue)%­h%C­(reset) - %C(bold cyan)%­aD%­C(r­eset) %C(bold green)­(%a­r)%­C(r­ese­t)%­C(bold yellow­)%d­%C(­res­et)%n'' %C(whi­te)­%s%­C(r­eset) %C(dim white)- %an%C(­reset)' --all

MERGING

Add commit from another branch
git cherry­-pick <co­mmi­t_h­ash>
Merge branches recurs­ively creating a new commmit
git merge <br­anc­h_n­ame>
Cancel merge
git merge --abort
Merge putting ours commit on base branch
git rebase <ba­se_­bra­nch­_na­me>
Cancel rebase
git rebase --abort
Squashes changes
git rebase -i
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Git Cheat Sheet