I have the branch master which tracks the remote branch origin/master.
I want to rename them to master-old both locally and on the remote. Is this possible?
For other users who tracked origin/master (and who always updated their local master branch via git pull), what would happen after I renamed the remote branch?
Would their git pull still work or would it throw an error that it couldn’t find origin/master anymore?
Then, further on, I want to create a new master branch (both locally and remote). Again, after I did this, what would happen now if the other users do git pull?
I guess all this would result in a lot of trouble. Is there a clean way to get what I want? Or should I just leave master as it is and create a new branch master-new and just work there further on?
The closest thing to renaming is deleting and then recreating on the remote. For example:
However, this has a lot of caveats. First, no existing checkouts will know about the rename – Git does not attempt to track branch renames. If the new
masterdoesn’t exist yet, git pull will error out. If the newmasterhas been created. the pull will attempt to mergemasterandmaster-old. So it’s generally a bad idea unless you have the cooperation of everyone who has checked out the repository previously.Note: Newer versions of Git will not allow you to delete the master branch remotely by default. You can override this by setting the
receive.denyDeleteCurrentconfiguration value towarnorignoreon the remote repository. Otherwise, if you’re ready to create a new master right away, skip thegit push remote :masterstep, and pass--forceto thegit push remote masterstep. Note that if you’re not able to change the remote’s configuration, you won’t be able to completely delete the master branch!This caveat only applies to the current branch (usually the
masterbranch); any other branch can be deleted and recreated as above.