0

I have an old master branch which is broken and should not be used.
And I have a new branch master2 which is good and further changes should be committed to it.

Can I rename the old master to master-old and rename master2 to become the new master?

Will that be an issue?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Zach
  • 5,715
  • 12
  • 47
  • 62
  • 1
    If you want to keep the history without an extra branch floating around: `git merge -s ours master` (check the syntax) into `master2`, then merge `master2` into `master`. Done! – ta.speot.is Jan 27 '18 at 03:18
  • 1
    you could just delete your old master – Daniel A. White Jan 27 '18 at 03:20
  • Obviously yes to the first question. Matter of opinion to the second. The main thing to consider is how many remotes you have. – Mad Physicist Jan 27 '18 at 03:21
  • 1
    Possible duplicate of [Rename master branch for both local and remote Git repositories](https://stackoverflow.com/questions/1526794/rename-master-branch-for-both-local-and-remote-git-repositories) – phd Jan 27 '18 at 13:07

1 Answers1

4

Locally, you can rename whatever and whenever you want.
But if you intend to push, exercise caution.

Whenever you change a branch history (like here renaming/replacing one branch by another), you will have to git push --force that branch to the remote.

If you are the only one working on that repository, that is perfectly OK.
But if you are working with other collaborators who would have cloned/used the old master branch, you will need to advertise and communicate that change first.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250