Renaming a branch in GitHub

前端 未结 15 2305
面向向阳花
面向向阳花 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:05

    In my case, I needed an additional command,

    git branch --unset-upstream
    

    to get my renamed branch to push up to origin newname.

    (For ease of typing), I first git checkout oldname. Then run the following:

    git branch -m newname
    git push origin :oldname*or*git push origin --delete oldname
    git branch --unset-upstream
    git push -u origin newname or git push origin newname

    This extra step may only be necessary because I (tend to) set up remote tracking on my branches via git push -u origin oldname. This way, when I have oldname checked out, I subsequently only need to type git push rather than git push origin oldname.

    If I do not use the command git branch --unset-upstream before git push origin newbranch, git re-creates oldbranch and pushes newbranch to origin oldbranch -- defeating my intent.

提交回复
热议问题