Register
Home Projects Help

Git Cheat Sheet

Cloning the Spree repository from Github

git clone git://github.com/schof/spree.git spree

Cloning a Spree fork from Github (your own or someone else’s)

git clone git://github.com/yourname/spree.git spree-fork

Updating your fork to grab the latest changes from the official repo

git remote add schof git://github.com/schof/spree.git
git checkout -b schof/master
git pull schof master
git checkout master
git merge schof/master

Subsequent merge with the mainline (after your first merge above)

git checkout schof/master
git pull schof master
git checkout master
git merge schof/master

Throw away your uncommitted changes

git reset --hard

List the branches in your fork (and show current one)

git branch

Delete a branch (automatically stopping you if changes haven’t been merged)

git branch -d branch-name

Delete a branch (abandon all work on the branch regardless of whether it has been merged)

git branch -D branch-name

Cherry pick a single change from the official repository (or someone else’s fork)

git checkout -b cherry-pick
git fetch git://github.com/schof/spree.git
git cherry-pick e0277f3cd2c0952516a
git checkout master
git merge cherry-pick

Undo the last commit (assuming you haven’t pushed yet.)

git reset --soft HEAD^

Delete a remote branch (including github)

git push origin :branchname

Push your tags to a remote source (including github)

git push --tags

Apply a git patch file (as opposed to merging a github fork)

git apply patch_filename.diff

Make a diff of two branches (your master and schof/master) to see what is different

git diff master..schof/master

Create a branch based on the original schof/master instead of the current branch (if you screwed up your branch)

git checkout -b schof/master schof/master
git pull schof master
Export to HTML, TXT