Problem
Let’s say you made a local development branch, feature/inverse-matrix-calculation. After some commits and pushes to remote, you realized that you had named the branch the wrong way.
- the correct name:
feature/inverse-matrix-calculation - the current name:
future-inverse-matrix-calculation
Solution 1: checkout a new branch and delete the old
▶ Steps
- Create a new branch based on the current HEAD state at the
future-inverse-matrix-calculation. - Switch to the
future-inverse-matrix-calculationbranch - Delete the old one
- Set the correct upstream branch
▶ Commands
## Step 1 & 2
% git switch -c future-inverse-matrix-calculation feature/inverse-matrix-calculation
## Step 3
% git branch -D future-inverse-matrix-calculation
## Step 4
% git branch feature/inverse-matrix-calculation -u <remote branch>Solution 2: rename the branch
With the following command, you can rename a branch that was given the wrong name while keeping the upstream branch setting.
% git branch -m <old-name> <new-name>▶ Commands
## rename using -m/--move option
% git branch -m future-inverse-matrix-calculation feature/inverse-matrix-calculation