Question

So I created a branch to keep it as a snapshot of the current state of my project. I called it "v1".

I then refactored some code and commited to the master branch. So now I have the latest and greatest in master.

My question is: How do I maintain the old branch if someone submits a pull request to master? Is there an easy way to merge a pull request to both branches?

What I'm expecting is: if the file has changed a lot, then a conflict would appear. But if not, then it would merge only the changes introduced by the PR, even if the base of the PR is ahead of my legacy "v1" branch.

Was it helpful?

Solution

git fetch <remote>
git merge <remote>/<ref>

Where remote is the name of the remote branch that the pull request originated from and ref is the identifier of the commit (or branch) requesting the pull. So if you have the main repository as a remote named upstream and that repo has a pull request based off of 5d4434e (like this repository's pull request). You would run:

git fetch upstream
git merge upstream/5d4434e

This will merge that commit and all of the history missing from your local repo. If you wanted to merge just that commit's changes and not all of the history, you may want git cherry-pick upstream/5d4434e.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top