0

I have created a branch called "multiple_fixes" off my Dev branch and have been working there for a couple weeks. While I was working on my branch, several other people have created branches after I created mine, and have since made pull requests into the Dev branch.

Now, I am ready to merge my changes into Dev, but I have many files that are down-level from the current Dev branch. If I do a Pull Request, I will undo all the other changes that people have checked in.

How do I pull the current changes of Dev into my branch, without over-writing my work?

knittl
  • 246,190
  • 53
  • 318
  • 364
karozans
  • 53
  • 7
  • 2
    "If I do a Pull Request, I will undo all the other changes that people have checked in" -> No you won't. But you'll probably have to resolve conflicts. The common practice would be to rebase your branch on Dev, but tbh you should have made that a lot earlier, from time to time, not to be in that situation today. – Romain Valeri Nov 15 '22 at 15:35
  • 2
    Why do you think you will undo those changes? Git will _merge_ them, not override them (unless you overrode those changes in your branch). – eftshift0 Nov 15 '22 at 15:35

2 Answers2

1

Doing a merge of two branches will not overwrite the changes of one branch with changes of the other branch. Git will perform a three-way merge and will try to consolidate the changes. This works in most cases, but it can also fail; especially if the same line was updated in both branches or two lines very close together were modified. Such conflicts need to be resolved manually.

knittl
  • 246,190
  • 53
  • 318
  • 364
1

You should do rebase before merge, it will combine commits from your target branch to your current branch. If you have conflicts, git will start conflict resolver automatically with default editor.

git rebase origin dev
git push -f

or

git fetch --all
git checkout dev
git pull
git checkout multiple_fixes
git rebase dev
git push -f  

-f tag prevents commits duplication on pull-push, if your branch/repo settings allows it, if it's not, use git pull; git push

Mastermind
  • 454
  • 3
  • 11