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 rename a local Git branch?
- Git: How do I force “git pull” to overwrite local files?
- Differences between git pull origin master & git pull origin/master
- How do I discard unstaged changes in Git?
- Git: How to squash all commits on branch
- Undo git pull, how to bring repos to old state
- Undo git pull, how to bring repos to old state
- Is it better to create a Git repository at the root level or in the WordPress theme directory?
- WordPress and Git: How does Git interact with your IDE? [closed]
- 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 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
- How do I discard unstaged changes in Git?
- Git fetch remote branch
- Git: How do I force “git pull” to overwrite local files?
- 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 list all remote branches in Git 1.7+?
- 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 can I make git accept a self signed certificate?
- How to fetch all Git branches
- 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 can I revert multiple Git commits (already pushed) to a published repository?
- 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?
- What is the difference between ‘git pull’ and ‘git fetch’?
- 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?
- Git: cannot do a partial commit during a merge (SourceTree)
- Git: How do I force “git pull” to overwrite local files?
- What is the meaning of git reset –hard origin/master?
- How can I reset or revert a file to a specific revision?
- Else clause on Python while statement
- Branch from a previous commit using Git
- Not a valid object name: ‘master’
- Delete all local git branches
- Why does ‘git commit’ not save my changes?
- How do I copy a version of a single file from one Git branch to another?
- Git pull origin
overwrites master? - How can I undo git reset –hard HEAD~1?
- How to clone all remote branches in Git
- Set up git to pull and push all branches
- git push to specific branch
- Git: Merge a Remote branch locally
- Update Git branches from master
- Get changes from master into branch in Git
- 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
- Do I commit the package-lock.json file created by npm 5?
- 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?
- What is the Git equivalent for revision number?
- 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?
- difference between git merge origin/master and git pull
- How can I display the current branch and folder path in terminal?
- 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?
- What’s a good (free) visual merge tool for Git? (on windows)
- Getting Started with Subversion, Git, or similar Version Control System to keep a History of my Files? [closed]
- Best way to version control WordPress template files?
- Should I use SVN or Git?
- WordPress Health Tool reporting version control as a critical issue
- storing database in version control
- Versioning and your WordPress site?
- Pull latest stable release via git [closed]
- How to make changes on WordPress site locally on live site?
- How should I be handling my theme version numbering?
- Version control with a team of non-developers
- Painless way to track remote Git repo for WordPress updates
- Questions about Git and WordPress [duplicate]
- How to change version numbers in themes from Official repository?
- Checking for a new version from WP Repos
- How to rename the wp-config.php file once under version control?
- When developing entire sites for clients, is it viable to version control the entire site? [duplicate]
- WordPress project under Mercurial, what’s an appropriate .hgignore file?
- How to use one git (github) repository for version control for multiple themes
- version control for wordpress? (wordpress folder and database at same time)
- If you already have a copy of the code, is there any reason to create a feature branch?