If you want to rename a branch while pointed to any branch, do:
git branch -m <oldname> <newname>
If you want to rename the current branch, you can do:
git branch -m <newname>
If you want to push the local branch and reset the upstream branch:
git push origin -u <newname>
And finally if you want to Delete the remote branch:
git push origin --delete <oldname>
A way to remember this is -m
is for “move” (or mv
), which is how you rename files. Adding an alias could also help. To do so, run the following:
git config --global alias.rename 'branch -m'
If you are on Windows or another case-insensitive filesystem, and there are only capitalization changes in the name, you need to use -M
, otherwise, git will throw branch already exists error:
git branch -M <newname>
Related Posts:
- How do I delete a Git branch locally and remotely?
- How do I delete a Git branch locally and remotely?
- How do I undo the most recent local commits in Git?
- What is the best (and safest) way to merge a Git branch into master?
- How do I rename a local Git branch?
- How can I switch to another branch in git?
- How to remove local (untracked) files from the current Git working tree
- Git merge hotfix branch into feature branch
- Git fetch remote branch
- How do I clone a specific Git branch? [duplicate]
- Git fetch remote branch
- How do I push a new local branch to a remote Git repository and track it too?
- How do I push a new local branch to a remote Git repository and track it too?
- Download single files from GitHub
- How do I push a new local branch to a remote Git repository and track it too?
- How to get just one file from another branch?
- Update Git branches from master
- Create a branch in Git from another branch
- How do I rename both a Git local and remote branch name?
- Create Git branch with current changes
- How to get the current branch name in Git?
- How do you create a remote Git branch?
- Move the most recent commit(s) to a new branch with Git
- Move the most recent commit(s) to a new branch with Git
- Make an existing Git branch track a remote branch?
- What does “Git push non-fast-forward updates were rejected” mean?
- How do I call git diff on the same file between 2 different local branches?
- How to get the current branch name in Git?
- How do you create a remote Git branch?
- How can I reset or revert a file to a specific revision?
- Branch from a previous commit using Git
- Not a valid object name: ‘master’
- How do I copy a version of a single file from one Git branch to another?
- Set up git to pull and push all branches
- Invalid VCS root mapping – 3 errors on my project
- Updates were rejected because the remote contains work that you do not have locally
- Move existing, uncommitted work to a new branch in Git
- how to reset develop branch to master
- Delete branches in Bitbucket
- How do I push a local Git branch to master branch in the remote?
- How to keep a branch synchronized/updated with master?
- How can I see the changes in a Git commit?
- How do I run git log to see changes only for a specific branch?
- How to create a local branch from an existing remote branch?
- How can I delete all Git branches which have been merged?
- How to find which git branch I am on when my disk is mounted on other server
- How to create a new branch from a tag?
- Pull latest stable release via git [closed]
- Version control with a team of non-developers
- Painless way to track remote Git repo for WordPress updates
- Questions about Git and WordPress [duplicate]
- What does cherry-picking a commit with Git mean?
- Differences between git pull origin master & git pull origin/master
- Undo a Git merge that hasn’t been pushed yet
- fatal: Not a git repository (or any of the parent directories): .git [duplicate]
- Git pushing to remote branch
- How do I undo ‘git add’ before commit?
- How do I discard unstaged changes in Git?
- How can I see the differences between two branches?
- What does “Changes not staged for commit” mean
- How can I merge multiple commits onto another branch as a single squashed commit?
- Why does git say “Pull is not possible because you have unmerged files”?
- Pushing empty commits to remote
- How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?
- Stash only one file out of multiple files that have changed with Git?
- What is git fast-forwarding? [duplicate]
- fatal: The current branch master has no upstream branch
- How to cherry-pick multiple commits
- What is “origin” in Git?
- Another git process seems to be running in this repository
- How do you stash an untracked file?
- How to git rebase a branch with the onto command?
- Remove a git commit which has not been pushed
- How can I make Git “forget” about a file that was tracked, but is now in .gitignore?
- How to remove files from git staging area?
- How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?
- How to undo git reset –soft to get my changes back?
- .gitignore and “The following untracked working tree files would be overwritten by checkout”
- git – Your branch is ahead of ‘origin/master’ by 1 commit
- Git: How to update/checkout a single file from remote origin master?
- Git pull origin
overwrites master? - ERROR: Error cloning remote repo ‘origin’
- Git: Merge a Remote branch locally
- How can I remove a commit on GitHub?
- What is the difference between ‘git remote update’, ‘git fetch’ and ‘git pull’?
- GitLab remote: HTTP Basic: Access denied and fatal Authentication
- What does git push origin HEAD mean?
- What to gitignore from the .idea folder?git intellij-idea gitignore webstorm
- How do you clone a Git repository into a specific folder?
- git checkout master error: the following untracked working tree files would be overwritten by checkout
- Git removing upstream from local repository
- Git pull – Please move or remove them before you can merge
- Unlink of file Failed. Should I try again?
- Resetting remote to a certain commit
- Change the location of the ~ directory in a Windows install of Git Bash
- difference between git merge origin/master and git pull
- Git checkout – switching back to HEAD
- Workflow for working with git and WordPress
- best practice on pushing staging development (database/uploads) to the live server
- how can I create a WP offline environment before releasing the websites? [closed]