Git Problems

Solutions to Common Issues

How do you rename a Git branch?

When working with your Git repositories, there will likely come a time when you wish to rename a Git branch that you’re working with. First, we’ll cover renaming a local Git branch and then renaming a remote Git branch; we will review the process using the cross-platform GitKraken Git GUI and the CLI.

Don’t risk messing up your repo history by renaming the wrong branch because you didn’t have enough visual context.

How do you rename a branch with GitKraken?

Now that we’ve shown you how to rename Git branches using the CLI, we’ll show you how to quickly do the same things using the GitKraken Git GUI for Windows, Mac, and Linux.

How do you rename a branch locally in GitKraken?

To rename a local branch using GitKraken, simply right-click on the branch and choose the Rename option from the context menu.

Next, type in your desired new branch name and hit Enter. The local branch will be renamed.

How do you rename a remote branch in GitKraken?

To update the remote branch you will have to change the upstream by right-clicking the branch and selecting Set Upstream from the context menu.

Next, enter the new branch name and click Submit. You can then push the new branch up to the remote using the Push toolbar button, or from the context menu.

Lastly, you’ll have to delete the old remote branch by right-clicking it and selecting Delete origin/branch-name from the context menu.

In just 2 clicks, GitKraken lets you quickly update local and remote branch names.

How do you rename a Git branch locally in the command line?

When you want to rename a Git branch locally, you can do so using the git branch command with the -m option.

If you want to rename the current branch you have checked out, you can simply pass in your desired new name:

git branch -m <new-branch-name>

Can you rename a local Git branch if you don’t have the branch checked out?

If you want to rename a different branch than the current branch you have checked out, you can use the same command, but pass in the current name of the branch followed by the new branch name:

git branch -m <branch-name><new-branch-name>

How do you rename a remote Git branch?

If the branch you are renaming has already been pushed to a remote, the upstream branch won’t change just because you renamed your local branch.

You can push the new branch to the remote and update the upstream using the git push command with the -u (or --set-upstream) option:

git push origin -u <new-branch-name>

Now, you will just have to delete the old branch from the remote using the git push command with the -d (or --delete) option:

git push origin -d <branch-name>

GitTip: Learn more about how to delete a remote branch in Git.

The process to rename a Git branch is much faster and more intuitive using the GitKraken Git GUI, and you can avoid making changes to the wrong data by mistake.

Additional Resources

Make Git Easier, Safer &
More Powerful

with GitKraken