Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.4k points)

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?

1 Answer

0 votes
by (27.5k points)

This following command will do the magic: 

$ git branch -m old-branch new-branch

To delete master:

$ git push remote :master  

To create master-old on remote:       

$ git push remote master-old      

To create a new local master:

$ git checkout -b master some-ref 

To create master on remote:

$ git push remote master    

Browse Categories