PASSWORD RESET

Your destination for complete Tech news

Git

How to rename a local Git branch?

316 0
< 1 min read

To rename a local Git branch, you can use the git branch command with the -m option, followed by the current name of the branch and the new name of the branch. For example:

git branch -m old-name new-name

This will rename the old-name branch to new-name.

If you are currently on the branch that you want to rename, you can use the git branch -m command without specifying the old name of the branch:

git branch -m new-name

This will rename the current branch to new-name.

It’s important to note that the git branch command only renames the branch locally. If you want to also rename the branch on the remote repository, you will need to push the renamed branch to the remote repository and delete the old branch.

To push the renamed branch to the remote repository, you can use the git push command with the -u option, which sets the upstream branch for the current branch.

git push -u origin new-name

To delete the old branch from the remote repository, you can use the git push command with the --delete option, followed by the name of the remote repository and the name of the branch you want to delete.

git push origin --delete old-name

This will delete the old-name branch from the origin remote repository.

You can also use the git push command with the -f option, which forces the update of the branch on the remote repository, even if it results in a non-fast-forward merge.

git push -f origin new-name

This will overwrite the old branch with the new branch on the origin remote repository.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.