This gist is intended for users who follow a forked repository/pull-request git workflow. Overtime, you may notice your forked repository's master branch becomes cluttered with "merged upstream/master into master"-type commits. These commits don't serve much of a purpose, and tend to clutter the commit history of any new pull requests you make.
By running the scripts below, we will delete your old master and create a new one based off of upstream/master. This will remove all of those unnecessary commits we don't want to see anymore. Based on the nature of how this works, you should be aware of a few things:
- This method relies on a force push, and "erases" git history. This is a bad practice, especially when working on the same repository with other people, so make sure you understand the consequences of a force push before you do it.
- Any work you have in your fork's
masterbranch must have been merged toupstream/masteror saved in another branch. If not, you will lose it all. - If you have existing branches with unmerged work in them, save yourself the chance of something going wrong and run a
git pull upstream masterin each of those branches to make sure this will end cleanly. This isn't required, but definitely recommended. - This script makes two key assumptions:
- Your fork and your upstream's primary branch is called
master - Your upstream source is labeled
upstream
- Your fork and your upstream's primary branch is called
If you're ready to start, then double check that your local repository has no outstanding changes in it, and get started:
git reset HEAD --hard
git checkout master
git checkout -b temp-master
git branch -D master
git fetch upstream
git checkout -b master upstream/master
git push origin master --force
git branch -D temp-masterOptionally reset your fork's dev branch to be based off the new master you created. Any existing feature branch(es) merged into dev will need to be merged in again.
git checkout master
git branch -D dev
git checkout -b dev
git push origin dev --force
git checkout master