7

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 merge origin/master
git checkout 

Is this enough for develop branch to be an identical copy to master

aynber
  • 22,380
  • 8
  • 50
  • 63
RaviPatidar
  • 1,438
  • 1
  • 18
  • 29
  • Why would you want to merge your `dev` branch back into `master` if it is "messy" and you want to "reset" it? – Thomas Stringer Jul 20 '15 at 14:47
  • 1
    possible duplicate of [Reset my local repository to be just like remote repository HEAD](http://stackoverflow.com/questions/1628088/reset-my-local-repository-to-be-just-like-remote-repository-head) – Andrew C Jul 20 '15 at 21:10

3 Answers3

9

Literally you have the answer to your question in the own question:

git checkout dev
git reset --hard master

git reset allows three possibilities:

  • soft: Move the branch to the point you decide, but it does not touch your index area and working directory.
  • mixed: (by default) the same as soft plus changes the Stage Area. Do not change your working directory.
  • hard: The same as mixed plus changes the working directory.

To understand better: git reset

blashser
  • 921
  • 6
  • 13
  • I dont know if this a new thing to git, or if its a vs code thing, but i did `git checkout master` (well main but same thing) and the files reverted to their previous state – PhantomSpooks Apr 26 '23 at 18:54
4

A merge will not be sufficient, since you will have the changes from both branches (develop + master) in the develop branch after the merge.

If you want to get rid of the current develop branch and create a new one, do the following:

# Check out the master branch
git checkout master

# Delete the current develop branch
git branch -D develop

# Create a new develop branch
git checkout -b develop

Only do this if you are really sure that you don't care about the current develop branch!

If you have a remote copy of the develop branch, you will have to take caution when pushing the new branch:

  • Either delete the remote branch first (before pushing the new one): git push origin :develop, or
  • Push with the --force switch

Both will change the history for other people that have previously pulled the current develop branch.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
0

This is not being asked for, and I hope it is not out of scope. Some years later, one should also check some helping tools instead of the mere git commands.

If lazygit is installed, just type lazygit in the command line in the folder of the git repository. Checkout the non-master branch you want to reset by pressing Space when the non-master branch is marked in "Local Branches". Go down with the arrow key and mark the "master" branch. Press x for the menu, then Space on the marked g (or g without the menu if you know it by heart).

enter image description here

Choose the reset mode. Any mode can be recovered by reflog.

enter image description here

Go down two items with the arrow key and choose --hard

questionto42
  • 7,175
  • 4
  • 57
  • 90