How to Reset Develop Branch to Master

How to Reset Develop Branch to Master

I have develop & master branches, my develop branch is messy now and i would like to reset it and make it as a copy of my master. i'm not sure if merging the master into develop will make both of them identical. after trying to merge i got many conflicts i solved them using:

git checkout develop
git merge origin/master
//got many conflicts
git checkout . --theirs

is this enough for develop branch to be an identical copy to master ?

Thanks

3

6 Answers

if you just want them to be the same thing

then

//from Develop and assuming your master is up to date with origin/master
git reset --hard master
3

If you want to make develop be identical to master, the simplest way is just to recreate the pointer:

git branch -f develop master

Or, if you already have develop checked out:

git reset --hard develop master

Note however that both of these options will get rid of any history that develop had which wasn't in master. If that isn't okay, you could preserve it by instead creating a commit that mirrored master's latest state:

git checkout develop
git merge --no-commit master
git checkout --theirs master .
git commit
9

Reset Last Commit

git reset HEAD~ 
1

For example making staging branch identical to develop, one could simply recreate the pointer:

First make sure your local develop branch is up to date with origin/develop by running: git checkout develop && git pull origin develop

Then checkout your target branch (in this case staging) git checkout staging

And finally but not least reset target branch git reset --hard develop

Push changes by brute force (git will complain because local pointer have different address) git push -f

And that would be pretty much it!

If all else fails, you can delete your current branch and just directly recreate it from master.

git branch -D develop
git checkout master
git checkout -b develop
1

I'm a bit late to the party, however, after merging my dev branch into the master and pushing to the server, I do the following:

git fetch

git checkout development

git merge origin/master

git push

The the dev branch is one commit ahead of the master branch, and other developers don't have to worry about all commits in the development branch being reset.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.