DEV Community

Liang Wang
Liang Wang

Posted on

Git rename branch

I have a local branch with a long name so I want to rename it shorter.

Rename a local branch by this command

git branch -m oldName newName

Update:
After I rename the local branch and try to push code, I got this error:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:oldName

To push to the branch of the same name on the remote, use

    git push origin HEAD
Enter fullscreen mode Exit fullscreen mode

So I followed the advice and git push origin HEAD:oldName then it works like a charm.

Top comments (0)