Skip to content

Instantly share code, notes, and snippets.

@cathyxz
Last active December 19, 2018 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cathyxz/30b535038a5b48158108591acba1e59e to your computer and use it in GitHub Desktop.
Save cathyxz/30b535038a5b48158108591acba1e59e to your computer and use it in GitHub Desktop.
Git / Github Swiss Army Knife

I need to

pull someone else's repo

git remote add coworker git://path/to/coworkers/repo.git
git fetch coworker
git checkout --track coworker/foo
git checkout foo
git pull

grab a coworker's work from an unmerged PR

Download a patch by adding .patch to the url of the PR or the commit, for example: https://patch-diff.githubusercontent.com/raw/ampproject/amphtml/pull/19770.patch https://github.com/ampproject/amphtml/commit/658c9133650e72a087b1ba184486db1fd9b8b047.patch Save this patch as foo.patch. On your branch, run:

git apply name-of-file.patch

work off of an unmerged branch

git checkout their-branch # see pulling someone else's repo above
git checkout -b my-dependent-branch

rebase / update based on their new changes.

git rebase -i their-branch

merge my changes after their changes hit master

git rebase -i upstream/master

and drop any duplicate commits.

revert everything to one particular commit

This will reset to commit at hash A.

git checkout -f A -- .
git commit'

Or do

git revert --no-commit HEAD~3..

This reverts the last 2 commits.

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