0% found this document useful (0 votes)
200 views1 page

Git Command Cheat Sheet Guide

Uploaded by

Bob Yao
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views1 page

Git Command Cheat Sheet Guide

Uploaded by

Bob Yao
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cheat Sheet

Create Change Update

From existing data Using your favorite editor / IDE Fetch latest changes from origin
cd ~/my_project_dir git fetch
git init this does not merge them
git add . Pull latest changes from origin
From existing repo Revert git pull
git clone ~/existing/repo ~/new/repo does a fetch followed by a merge
git clone [email protected]:dir/project.git
Return to the last committed state Apply a patch that someone sent you
default protocol is ssh git checkout -f | git reset --hard git am -3 patch.mbox
you cannot undo a hard reset In case of conflict, resolve the conflict and
Revert the last commit git am --resolve
Browse git revert HEAD
Creates a new commit
Revert specific commit
Files changed in working directory
git status
git revert $id Commit
Creates a new commit
Changes to tracked files
Fix the last commit
git diff Commit all local changes
git commit -a --amend
Changes between ID1 and ID2 git commit -a
after editing the broken files
git diff <ID1> <ID2>
Checkout the ID version of a file
History of changes
git checkout <ID> <file>
git log
Who changed what and when in a file
git blame <file> Publish
A commit identified by ID Branch
git show <ID> Prepare a patch for other developers
A specific file from a specific ID git format-patch origin
List all branches Push changes to origin
git diff <ID>:<FILE>
git branch git push [origin] [branch]
Search for patterns
Switch to the BRANCH branch Make a version or milestone
git grep <pattern> [path]
git checkout <BRANCH> git tag <version_name>
Merge branch B1 into branch B2
git checkout <B2>
git merge <B1>
Useful tips Create branch based on HEAD
git branch <BRANCH>
Create branch based on another
Get help
git help [command]
git checkout <new> <base> Configuration
Delete a branch
Create empty branch
git branch -d <branch> git config [--global]
git symbolic-ref HEAD
refs/heads/newbranch global is stored in ~/.gitconfig
rm .git/index user
git clean -fdx Resolve merge conflicts user user.name $name
<do work> user.email $email
git add your files View merge conflicts color
git commit -m 'Initial commit' git diff color color.ui auto
Graphical log View merge conflicts against base file github
git log --graph git diff --base <FILE> github github.user $user
git log --graph --pretty=oneline -- View merge conflicts against other changes github.token $token
abbrev-commit git diff --theirs <FILE> optimisation
Push branch to remote View merge conflicts against your changes optimisation pack.threads 0
git push <origin> <branch> git diff --ours <FILE> diff.renamelimit 0
Delete remote branch and locally After resolving conflicts, merge with do not use on low memory p
git push <origin> :<branch> git add <CONFLICTING_FILE> windows
git branch -d <branch> git rebase --continue windows core.autocrlf true

http://github.com/AlexZeitler/gitcheatsheet This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License

You might also like