I have a master branch / Production which is in a clean state right now and also a develop branch which somewhere along the way went awry with numerous people working on branches and committing changes. What I want to do is reset the develop branch to be equal with master again but not affect the actual master branch / Production. So essentially develop remains develop but looks just like master.
Is this safe?
git checkout develop git reset --hard master
CodePudding user response:
Is this safe?
Yes, it's safe, however, a better question might be whether or not it's a good idea. There is a step you left out which highlights this point. Here's how you can reset develop
to master
:
git fetch
git switch develop
git reset --hard origin/master
git push --force
Note the last step is a force push, which is necessary in order to rewrite the develop
branch on your remote server. It's generally frowned upon to force push shared branches, because this affects everyone who is using that branch, as all of their in-progress branches will need to be rebased using the --onto
flag to fix them. Furthermore, in your case, you likely have a lot of good work that is on develop
that you will lose, and all that work will need to be rebased and then re-merged into the new develop
.
Typically the better approach here would be to isolate the problem commit(s) and just revert those (or add new commits with the fix) on develop
. It sounds like you attempted that and are ready to throw in the towel and go with the hard reset. That's OK as long as you and your team understand the effects of doing so.