how to reset develop branch to master

GitVersion ControlBranch

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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

Solution 3 - Git

Reset Last Commit

git reset HEAD~ 

Solution 4 - Git

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!

Solution 5 - Git

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

Solution 6 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontrrrrrrmView Question on Stackoverflow
Solution 1 - GitTim JarvisView Answer on Stackoverflow
Solution 2 - GitAmberView Answer on Stackoverflow
Solution 3 - GitSanjay SikdarView Answer on Stackoverflow
Solution 4 - Gitd1jhoni1bView Answer on Stackoverflow
Solution 5 - GitGiboltView Answer on Stackoverflow
Solution 6 - GitShea LavingtonView Answer on Stackoverflow