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 developgit merge origin/master//got many conflictsgit checkout . --theirs

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

Thanks

6

Best Answer


If you want the two branches to be the same then

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

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 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 developgit merge --no-commit mastergit checkout --theirs master .git commit

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

git branch -D developgit checkout mastergit checkout -b develop

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 branchgit 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!

Reset Last Commit

git reset HEAD~ 

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.