Git Cheat Sheet

ADVERTISEMENT

Commands Sequence
Git
Cheat Sheet
the curves indicate that the command on the right is usually
executed after the command on the left. This gives an idea of
the flow of commands someone usually does with Git.
Remember:
git command --help
Global Git configuration is stored in $HOME/.gitconfig
(git config
--help)
CREATE
BROWSE
REVERT
UPDATE
COMMIT
CHANGE
BRANCH
PUBLISH
push
commit
status
reset
pull
init
checkout
log
fetch
clone
checkout
branch
format-patch
show
revert
merge
diff
am
branch
Create
Concepts
Git Basics
From existing data
cd ~/projects/myproject
master
: default development branch
git init
origin
: default upstream repository
git add .
HEAD
: current branch
HEAD^ : parent of HEAD
From existing repo
HEAD~4 : the great-great grandparent of HEAD
git clone ~/existing/repo ~/new/repo
git clone
Revert
git clone
Show
Return to the last committed state
git reset --hard
Publish
you cannot undo a hard reset
Update
!
!
Files changed in working directory
git status
Revert the last commit
Fetch latest changes from origin
Commit all your local changes
git revert HEAD
Creates a new commit
Changes to tracked files
git fetch
git commit -a
Revert specific commit
git diff
(but this does not merge them).
git revert $id
Creates a new commit
Pull latest changes from origin
Prepare a patch for other developers
What changed between $ID1 and $ID2
git pull
git format-patch origin
Fix the last commit
git diff $id1 $id2
(does a fetch followed by a merge)
git commit -a --amend
History of changes
Push changes to origin
Apply a patch that some sent you
(after editing the broken files)
git log
git push
git am -3 patch.mbox
Checkout the $id version of a file
(in case of a conflict, resolve and use
History of changes for file with diffs
git checkout $id $file
git am --resolved
)
git log -p $file $dir/ec/tory/
Mark a version / milestone
Branch
git tag v1.0
Who changed what and when in a file
git blame $file
Switch to the $id branch
git checkout $id
A commit identified by $ID
To view the merge conclicts
Finding regressions
git show $id
git diff
(complete conflict diff)
git bisect start
(to start)
Merge branch1 into branch2
git diff --base $file
(against base file)
git bisect good $id
($id is the last working version)
git checkout $branch2
A specific file from a specific $ID
git diff --ours $file
(against your changes)
git bisect bad $id
($id is a broken version)
git merge branch1
git diff --theirs $file
(against other changes)
git show $id:$file
git bisect bad/good
(to mark it as bad or good)
Create branch named $branch based on
git bisect visualize
(to launch gitk and mark it)
All local branches
the HEAD
git bisect reset
(once you're done)
To discard conflicting patch
git branch
git branch $branch
git reset --hard
(star '*' marks the current branch)
Check for errors and cleanup repository
git rebase --skip
Create branch $new_branch based on
branch $other and switch to it
git fsck
Cheat Sheet Notation
git gc --prune
git checkout -b $new_branch $other
After resolving conflicts, merge with
$id : notation used in this sheet to represent either a
Search working directory for foo()
Delete branch $branch
git add $conflicting_file
(do for all resolved files)
commit id, branch or a tag name
git rebase --continue
git branch -d $branch
git grep "foo()"
$file : arbitrary file name
$branch : arbitrary branch name
Zack Rusin
Based on the work of:
Sébastien Pierre
Xprima Corp.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go