Renaming a branch in GitHub

前端 未结 15 2306
面向向阳花
面向向阳花 2020-12-02 03:28

I just renamed my local branch using

git branch -m oldname newname

but this only renames the local version of the branch. How can I rename

15条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 04:01

    Simple as that. In order to rename a Git branch locally and remotely use this snippet (tested and works like a charm):

    git branch -m  
    git push origin :
    git push --set-upstream origin 
    

    Explanation:

    1. Rename step:

    Git reference: With a -m or -M option, will be renamed to . If had a corresponding reflog, it is renamed to match , and a reflog entry is created to remember the branch renaming. If exists, -M must be used to force the rename to happen.

    1. Delete step:

    Git reference: git push origin :experimental Find a ref that matches experimental in the origin repository (e.g. refs/heads/experimental), and delete it.

    1. Update on remote repository step (upstream reference for tracking):

    Git reference: --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. For more information, see branch..merge in git-config[1].

提交回复
热议问题