Created
December 28, 2010 17:57
-
-
Save trentm/757481 to your computer and use it in GitHub Desktop.
my current git cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a new remote repo. Examples: | |
git remote add origin git@github.com:trentm/eol.git | |
git remote add upstream git://github.com/ry/node.git | |
git format-patch HEAD^ | |
git format-patch HEAD~2 | |
# Pull in upstream changes. | |
# http://help.github.com/forking/ | |
# Using fetch/merge instead of pull because (a) can help make | |
# merge conflicts more user-friendly and (b) explicit 'fetch' | |
# pulls all branches. | |
git fetch upstream | |
git merge upstream/master | |
# rebase a topic branch (shorter: git rebase master topic) | |
git checkout topic | |
git rebase master | |
# push changes back to github | |
git push origin master # shorter: `git push` | |
git push origin topic # push a topic branch | |
# Get a local branch name to track a remote one. E.g. say I had a | |
# local "replhack" branch of node.js, pushed to my Github fork, then moved | |
# machines and wanted to have that again. | |
git branch --track replhack remotes/origin/replhack | |
# Prune deleted remote branches from local clone. Good to run this occassionally. | |
git remote prune REMOTENAME | |
# Deleting a remote branch (http://help.github.com/remotes/) | |
git push REMOTENAME :BRANCHNAME | |
# Using a topic branch (http://progit.org/book/ch3-2.html) | |
git checkout -b mytopic | |
... make edits and commits and (I think) pushes | |
# - update from parent branch occassionally (presuming parent is "master" here) | |
git checkout master | |
git pull origin master | |
# - and rebase | |
git checkout mytopic | |
git rebase master | |
# - come time to merge back to parent | |
git checkout master | |
git merge mytopic | |
# - and push it | |
git push origin master | |
# - delete the finished branch | |
git push origin :mytopic # to delete remotely, if you pushed it | |
git branch -d mytopic | |
# submodules | |
git submodule init | |
git submodule update --recursive | |
# delete/drop last commit (if not pushed, http://nakkaya.com/2009/09/24/git-delete-last-commit/) | |
git reset --hard HEAD~1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment