Skip to content

Instantly share code, notes, and snippets.

@pjobson
Last active July 26, 2018 15:30
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 pjobson/04228f239585dca35836a586ca41feda to your computer and use it in GitHub Desktop.
Save pjobson/04228f239585dca35836a586ca41feda to your computer and use it in GitHub Desktop.
git notes

Rebase master into a branch.

git checkout branchName
git fetch
git rebase origin/master

Rebase a branch into a branch

git checkout branchName
git fetch
git rebase origin/branchToRebase

Rebase Example

  • <sha> is the commit prior to the screw up.
  • <branch_name> is the name of the branch you want to push the changes to.
  • Note -f must be used to force git to not throw annoying error messages and make weird stuff happen to your branch.
git rebase -i <sha>

git checkout <sha> path/to/file.123.js
git checkout <sha> path/to/file.132.js
git checkout <sha> path/to/file.312.js
git checkout <sha> path/to/file.321.js
git checkout <sha> path/to/file.231.js
git checkout <sha> path/to/file.213.js

git commit --amend

git push -f origin <branch_name>

Remove Local Branches which Do Not Exist on Remote

git fetch -p && \
   for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; \
   do git branch -D $branch; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment