100% found this document useful (3 votes)
908 views1 page

Git Cheat Sheet

This document provides a cheat sheet for common Git commands organized into categories for creating, updating, and publishing repositories as well as resolving conflicts and getting help. It includes commands for initializing repositories, tracking changes, committing updates, pushing to remote repositories, reverting commits, resolving conflicts, and more. Additional resources for learning more about Git and version control are also listed.

Uploaded by

shawnjgoff
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
100% found this document useful (3 votes)
908 views1 page

Git Cheat Sheet

This document provides a cheat sheet for common Git commands organized into categories for creating, updating, and publishing repositories as well as resolving conflicts and getting help. It includes commands for initializing repositories, tracking changes, committing updates, pushing to remote repositories, reverting commits, resolving conflicts, and more. Additional resources for learning more about Git and version control are also listed.

Uploaded by

shawnjgoff
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
You are on page 1/ 1

Git Cheat Sheet Legend

<required>
[optionnal]
Get Help!
git help [command]
Learn More!
http://book.git-scm.com/
http://learn.github.com/
http://help.github.com/
http://progit.org/book/
http://gitready.com/

Create Update Workflow


From existing data Fetch latest changes from origin
cd ~/projects/myproject git fetch
this does not merge them
git init
git add .
Pull latest changes from origin update
git pull
From existing repo does a fetch followed by a merge branch pull
Apply a patch that someone sent you
git clone ~/existing/repo ~/new/repo git am -3 patch.mbox checkout fetch
git clone [email protected]:dir/project.git In case of conflict, resolve the conflict and
default protocol is ssh git am --resolve branch merge
Remote repository for existing local data
mkdir repo.git && cd repo.git
am
git init --bare [--shared=group]
see help for info
Publish browse
Commit all local changes status change
create publish
Show git commit -a
log
using your
favorite editor commit
Prepare a patch for other developpers init push
Files changed in working directory git format-patch origin show commit
git status clone format-patch
Push changes to origin diff
Changes to tracked files git push [origin] [branch]
branch revert
git diff
Make a version or milestone
Changes between ID1 and ID2 git tag <version_name>
reset
git diff <ID1> <ID2> checkout
History of changes revert
git log Revert
History of changes with files changed Return to the last committed state
git whatchanged git checkout -f | git reset --hard
Who changed what and when in a file ! you cannot undo a hard reset
git blame <file> Revert the last commit
A commit identified by ID git revert HEAD Resolve
git show <ID>
Creates a new commit
Revert specific commit Useful tips merge conflicts Configuration
A specific file from a specific ID git revert $id Get help !!!
Creates a new commit View merge conflicts git config [--global]
git diff <ID>:<FILE> Fix the last commit git help [command] git diff
global is stored in ~/.gitconfig
git commit -a --amend Create empty branch
All local branches View merge conflicts against base file
after editing the broken files git symbolic-ref HEAD refs/heads/newbranch
git branch git diff --base <FILE> user.name $name
star "*" marks the current branch Checkout the ID version of a file rm .git/index user
user.email $email
Search for patterns git checkout <ID> <file> git clean -fdx View merge conflicts against other changes
git grep <pattern> [path] <do work> git diff --theirs <FILE>
color color.ui auto
git add your files
View merge conflicts against your changes
git commit -m 'Initial commit' github.user $user
Branch Graphical log
git diff --ours <FILE>
Discard a conflicting patch
github
github.token $token
git log --graph
Switch to the BRANCH branch git reset --hard
git log --graph --pretty=oneline --abbrev-commit pack.threads 0
git checkout <BRANCH> git rebase --skip optimisation
Push branch to remote diff.renamelimit 0
Merge branch B1 into branch B2 After resolving conflicts, merge with do not use on low memory pc
git push <origin> <branch>
git checkout <B2> git add <CONFLICTING_FILE>
Delete remote branch and locally windows core.autocrlf true
git merge <B1> git rebase --continue
git push <origin> :<branch>
Create branch based on HEAD git branch -d <branch>
git branch <BRANCH>
Create branch based on another
git checkout <new> <base> master is the default development branch
Delete a branch origin is the default upstream repository
HEAD is the current branch This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License : http://creativecommons.org/licenses/by-sa/3.0/
git branch -d <branch>

You might also like