Renaming branches remotely in Git

后端 未结 9 1199
执笔经年
执笔经年 2020-11-28 17:07

If there is a repository that I only have git:// access to (and would usually just push+pull), is there a way to rename branches in that repository in the same

9条回答
  •  一向
    一向 (楼主)
    2020-11-28 17:45

    You just have to create a new local branch with the desired name, push it to your remote, and then delete the old remote branch:

    $ git branch new-branch-name origin/old-branch-name
    $ git push origin --set-upstream new-branch-name
    $ git push origin :old-branch-name
    

    Then, to see the old branch name, each client of the repository would have to do:

    $ git fetch origin
    $ git remote prune origin
    

    NOTE: If your old branch is your main branch, you should change your main branch settings. Otherwise, when you run $ git push origin :old-branch-name, you'll get the error "deletion of the current branch prohibited".

提交回复
热议问题