Git – How to maintain a forked git repo with feature branches that upstream won’t pull

etiquetteforkinggitopen sourceworkflows

So here's a typical workflow on Github…

  1. Like some project -> fork it -> git clone https://github.com/you/someproject.

  2. Open project. Like what you see, but make some changes.

  3. Having been careful to work only in a feature-branch (git checkout -b some-feature), you decide to make a pull request with the upstream maintainer – after having pushed your feature-branch to your Github fork.

  4. Maintainer, for whatever reason, declines the pull.

For example.. here is a failed pull request that I submitted that matches the above scenario...

Now typically, if the maintainer HAD merged the pull… the workflow would be simple… On my local machine, I would commit any local changes on whatever feature-branch I was on at the time… git fetch --all, git checkout master, git pull upstream --ff-only. Then replay my changes on top of that, as desired…

BUT…

What if I decide that you want to continue working off the changes to my fork, regrdless… yet still want to be able to track + merge changes that happen upstream? Ordinarily, I would delete the feature branch, and go on my way.. How can you maintain a master branch that is able to be merged upstream, yet maintains your fork's features while being "permanently detached" from upstream's HEAD?

Best Answer

Regardless of the use of your scenario, here is how you can do it:

  • master is exactly of the version the upstream master has
  • custom is your own "master" branch in which you have applied the formatting changes
  • all feature branches are branched off custom if you don't want them to be pulled into upstream master
  • Once master is updated, you rebase custom to master and then you rebase your feature branches to custom

With this strategy it should work. But keep in mind that every change you make in a feature branch based upon custom won't be accepted into upstream master.

Related Topic