Show Menu
Cheatography

Git cheat sheet Cheat Sheet (DRAFT) by

My personal cheat sheet for git

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

Creating

 
To create a local repository
cd ~/proj­ect­s/m­ypr­oject
git init
git add .

To clone from a remote repository (possible ways to do it)
git clone /exist­ing­/repo /new/repo
git clone git://­hos­t.o­rg/­pro­jec­t.git
git clone ssh://­you­@ho­st.o­rg­/pr­oj.git

Local

git checkout [-b]
Switches HEAD to given branch -b for creating a branch
git commit [--amend]
Adds a new commit; --amend for a slight change to current commit
git tag
Adds a tag
git describe
Describes how far is the nearest ancestor with a tag
git merge
Merges two commits
git log
Displays changes to the project
git rebase [-i]
Creates a copy of commits from HEAD to a given commit; -i for an intera­ctive mode
git branch [-f] [-u] [-d]
Creates a new branch; -f for force; -u for specifying which branch to track; -d for deleting a branch;
git cherry­-pick
Adds to the HEAD commits that are not ancestors in a given order
git reset
Deletes a HEAD commit
git revert
Creates a new commit that undoes the changes from a previous commit
Main difference between git merge and git rebase is that rebase makes commits to be in a one line under each other on a tree, which leads to loosing the order of changes. Merge creates a new commit which keeps the order of changes in the project. It's just the matter of tree simplicity and keeping changes between them.
 

Remote

git clone
Clones from a remote repository
git fetch
Downloads all commits, but doesn't merges or rebases them in a local project
git pull [--rebase]
Combines git fetch and git merge; --rebase for git rebase instead of git merge
git push
Uploads commits
Fetch, pull and push have a specific syntax if we want to specify the source and destin­ation commits. Basically we can use two forms:

git fetch/­pul­l/push destin­ation source for whole commit tree branch

git fetch/­pul­l/push origin source­:de­sti­nation for specific commits