public
Description: Spree is a complete open source e-commerce solution for Ruby on Rails.
Home | Edit | New

Git Cheat Sheet

Cloning the Spree repository from Github

git clone git://github.com/railsdog/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 railsdog git://github.com/railsdog/spree.git
git checkout -b railsdog/master
git pull railsdog master
git checkout master
git merge railsdog/master

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

git checkout railsdog/master
git pull railsdog master
git checkout master
git merge railsdog/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/railsdog/spree.git
git cherry-pick -x 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 railsdog/master) to see what is different

git diff master..railsdog/master

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

git checkout -b railsdog/master railsdog/master
git pull railsdog master

Work on an “upstream” branch other then master

git checkout --track -b <local name> origin/<remote name>

Note: this creates a local branch based on the upstream branch and switches your working copy to that branch.

Examine an earlier version of your source

Example: You want to create a local branch to examine the initial commit

git checkout c32e3074f4130
git checkout -b initial_commit

Tell git to remove files that are deleted in file system but not yet removed from index (instead of git rm on all of them)

git add -u
Last edited by stephp, Wed May 20 16:10:59 -0700 2009
Home | Edit | New
Versions: