Make the current Git branch a master branch

前端 未结 14 1908
悲&欢浪女
悲&欢浪女 2020-11-22 05:29

I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.

Then, tens of commits later, I realized the branch is in muc

14条回答
  •  北海茫月
    2020-11-22 06:16

    Edit: You didn't say you had pushed to a public repo! That makes a world of difference.

    There are two ways, the "dirty" way and the "clean" way. Suppose your branch is named new-master. This is the clean way:

    git checkout new-master
    git branch -m master old-master
    git branch -m new-master master
    # And don't do this part.  Just don't.  But if you want to...
    # git branch -d --force old-master
    

    This will make the config files change to match the renamed branches.

    You can also do it the dirty way, which won't update the config files. This is kind of what goes on under the hood of the above...

    mv -i .git/refs/new-master .git/refs/master
    git checkout master
    

提交回复
热议问题