Skip to content

Instantly share code, notes, and snippets.

@iangilman
Last active June 29, 2017 14:30
Show Gist options
  • Save iangilman/1097883 to your computer and use it in GitHub Desktop.
Save iangilman/1097883 to your computer and use it in GitHub Desktop.
Ian's git cheat-sheet

Ian's git cheat-sheet

Forks

To get set up, see: http://help.github.com/fork-a-repo/

Each time you want to get the latest from upstream, use:

$ git fetch upstream
$ git merge upstream/master

To add a new server to an existing local repo (in this case for iangilman/openseadragon):

$ git remote add iangilman [email protected]:iangilman/openseadragon

To then push to that server:

$ git push iangilman <branchname>

Branches

To see what's changed between branch foo and master: git diff master..foo

To rename a branch: git branch -m old_name new_name

To apply a single commit from another branch: git cherry-pick <commit-id>

To delete a branch: git branch -D <branch-name>

Create a patch with changes between the current branch and master: git format-patch master --stdout > foo.patch

Pull the last 3 commits off of master into a new branch:

git branch newbranch
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout newbranch

Push a branch to the server and connect it for future pulls: git push -u origin <branch-name>

Merging

To abort a merge: git reset --merge

Reverting

You can add a new commit that reverts the file: do git checkout <commit-id> <path> and commit the result.

Other

http://ktown.kde.org/~zrusin/git/git-cheat-sheet-medium.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment