'How to replace master with dev branch in sourcetree
I'm using SourceTree. I have Dev branch and master branch. Dev is many version ahead of Master so there will be a lot of conflicts if I merge.
Is there anyway I can replace all the content in master branch with the dev content?
Solution 1:[1]
Dev is many version ahead of Master so there will be a lot of conflicts if I merge.
If there are merge conflicts when you try to merge dev into master, it is because there are commits on master that aren't on dev. And there are commits on dev that aren't on master. If this commits make changes to the same lines of code, then there will be merge conflicts.
However, if you manage master and dev branches correctly, there should never be merge conflicts. It is common to have commits on dev that aren't on master. This is the whole point of a dev branch. However, the only time I have commits on master that aren't on dev is when I make an emergency hotfix that merges directly into master to fix a critical bug immediately. After the crisis is resolved, I merge master into dev to avoid any future merge conflicts during regular deployments.
Is there anyway I can replace all the content in master branch with the dev content?
My suggestion is that you merge master into dev to resolve merge conflicts. I assume there is a reason for any commits on master that cause these conflicts. In the rare case that I've had to do this, I create a new branch on dev and then merge master into it. This allows me to work in such a way that I don't break the dev branch. This also allows me to make follow up commits in case I missed something in the merge process.
Since you want to keep the changes from dev, you can tell git to do it for you:
git checkout master
git merge -s theirs dev
or with a separate branch:
git checkout -b merge-in-dev master
git merge -s theirs dev
Now you have a branch that you can create a PR to master
As a last resort, you can just reset master to dev:
git checkout master
git reset --hard dev
git push -f
WARNING: This is destructive and basically impossible to recover from if you mess it up. For that reason, most git hosting services protect the master branch from force push. You will have to disable this protection. Be sure to renable it after you finish.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
