Branches can be renamed, for example, to fix a mistake in the branch name.
Local branches can be renamed easily. Renaming a branch simply changes the branch reference (i.e., the name used to identify the branch) — it is just a cosmetic change.
Preparation First, create the repo samplerepo-books
for this hands-on practical, by running the following commands in your terminal.
mkdir samplerepo-books
cd samplerepo-books
git init
echo "Horror Stories" >> horror.txt
git add .
git commit -m "Add horror.txt"
git switch -c textbooks
echo "Textbooks" >> textbooks.txt
git add .
git commit -m "Add textbooks.txt"
git switch master
git switch -c fantasy
echo "Fantasy Books" >> fantasy.txt
git add .
git commit -m "Add fantasy.txt"
git switch master
git merge --no-ff -m "Merge branch textbooks" textbooks
The above should give you a repo similar to the revision graph given below, on the left.
gitGraph BT: %%{init: { 'theme': 'default', 'gitGraph': {'mainBranchName': 'master'}} }%% commit id: "m1" branch textbooks checkout textbooks commit id: "[textbooks] t1" checkout master branch fantasy checkout fantasy commit id: "[fantasy] f1" checkout master merge textbooks id: "[HEAD → master] mc1"
→
[rename branches]
gitGraph BT: %%{init: { 'theme': 'default', 'gitGraph': {'mainBranchName': 'master'}} }%% commit id: "m1" branch study-books checkout study-books commit id: "[study-books] t1" checkout master branch fantasy-books checkout fantasy-books commit id: "[fantasy-books] f1" checkout master merge study-books id: "[HEAD → master] mc1"
Target Rename the fantasy
branch to fantasy-books
. Similarly, rename textbooks
branch to study-books
. The outcome should be similar to the revision graph above, on the right.
steps:
To rename a branch, use the git branch -m <current-name> <new-name>
command (-m
stands for 'move'):
git branch -m fantasy fantasy-books
git branch -m textbooks study-books
git log --oneline --decorate --graph --all # verify the changes
* 443132a (HEAD -> master) Merge branch textbooks
|\
| * 4969163 (study-books) Add textbooks.txt
|/
| * 0586ee1 (fantasy-books) Add fantasy.txt
|/
* 7f28f0e Add horror.txt
Note these additional switches to the log
command:
--all
: Shows all branches, not just the current branch.--graph
: Shows a graph-like visualisation (notice how*
is used to indicate a commit, and branches are indicated using vertical lines).
Right-click on the branch name and choose Rename...
. Provide the new branch name in the next dialog.

done!
SIDEBAR: Branch naming conventions
Branch names can contain lowercase letters, numbers, /
, dashes (-
), underscores (_
), and dots (.
).
You can use uppercase letters too, but many teams avoid them for consistency.
A common branch naming convention is to prefix it with <category>/
. Some examples:
feature/login-form
— for new features (origin/feature/login-form
could be the matching remote-tracking branch)bugfix/profile-photo
— for fixing bugshotfix/payment-crash
— for urgent production fixesrelease/2.0
— for prepping a releaseexperiment/ai-chatbot
— for “just trying stuff”
Although forward-slash (/
) in the prefix doesn't mean folders, some tools treat it kind of like a path so you can group related branches when you run git branch. Shown below is an example of how Sourcetree groups branches with the same prefix.
