rednoyz rednoyz - 26 days ago 5
Git Question

Git merge commits from a specific upstream release

Scenario: I've forked a github project and begun working on it (after adding the original project as a remote called 'upstream'). While working on my fork, a number of releases are made to the upstream project: v1.3-stable, v1.4-stable, v1.5-experimental, etc. Now I need to merge in the upstream commits to my master branch, but ONLY up to a specific release, for example, release v1.4-stable. What's the best workflow for this scenario?

Answer

Assuming v1.4-stable is a tag on the remote, you can those apply changes to your local repo by calling this from the branch that contains your work:

git fetch
git rebase --onto $(git rev-list -n1 v1.4-stable)

Rev-list finds the ID of the latest commit from v1.4-stable, after which those commits are replayed and your own work placed neatly on top. There will be conflicts if the remote has changed significantly since you forked.

If v1.4-stable is a branch on the remote you will instead want to do

git pull --rebase origin v1.4-stable