Reputation: 1327
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?
Upvotes: 9
Views: 3380
Reputation: 12381
Assuming v1.4-stable is a tag on the remote, you can apply those 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
Upvotes: 4
Reputation:
This assumes that v1.4-stable
is a a tag for a commit indicating the release, on the master branch.
Checkout master and pull the latest changes:
git checkout master
git pull --rebase
Next, rebase your development branch on top of this commit. Make sure your working tree is clean and your HEAD is pointing to your dev-branch:
git rebase v.14-stable
This command will change the base of your branch to include the v.1.4-stable
tagged commit, and all other releases preceding it.
Before rebase:
o---o---v.1.2---v.1.3---v.1.4---v.1.5-exp master
\
o---o---o dev
After:
o---o---v.1.2---v.1.3---v.1.4---v.1.5-exp master
\
o---o---o dev
Upvotes: 2
Reputation: 1323773
First make sure you are working in a dedicated branch for v1.5-experimental
.
Second, reset your master branch to upstream/v1.4 (make sure you don't have any work in progress: an hard reset would wipe them out)
git fetch upstream
git checkout master
git reset --hard upstream/v1.4
git push -f
Finally, rebase your v1.5-exprimental branch on top of master (that is on top of v1.4)
Fist, activate rerere (in case you have to do multiple rebase later on: that will record how you resolve similar conflicts in the past)
git config --global rerere.enabled true
Then rebase (replay your commit from your branch on top of v1.4):
git checkout v1.5-experimental
git rebase master
git push -f
The conflicts you will have to resolve there should only be conflicts of interest (concurrent modifications done both in upstream and in your experimental branch).
Upvotes: 1