Video

How to Rename a Git Branch | Local & Remote Branches Explained

How to Rename a Git Branch | Local & Remote Branches Explained

Created a branch with the wrong name? You don't need to delete your work and start over — a Git branch is just a movable reference to a commit, so renaming it changes the name and nothing else. Your commits stay exactly where they are.

This 2-minute explainer walks through the whole thing with a real Rails example: a branch called "payment" that should have followed the team's convention and been called "feature/payment-integration".

What's covered:

00:00 Wrong branch name? Rename it, don't recreate it
00:10 Why branch names matter for your team
00:25 A branch is a movable pointer — not a copy of your work
00:40 Renaming a local branch with git branch -m
01:00 Syncing the rename to the remote
01:25 What it buys you, and who it affects
01:45 Takeaway

The commands:

# rename the branch you're currently on
git branch -m feature/payment-integration

# rename a different local branch (works from anywhere)
git branch -m payment feature/payment-integration

# push the new name and set upstream tracking
git push -u origin feature/payment-integration

# then delete the old remote branch
git push origin --delete payment

# confirm the tracking
git branch -vv

Three things worth remembering:

1. Renaming locally does NOT rename the remote branch. The rename is local until you push.
2. Push the new name FIRST, delete the old one SECOND. Never the other way round — deleting first can leave the branch with no remote copy at all.
3. Coordinate with your team. Anyone using the old remote branch may need to update their local branches and tracking configuration, and open pull requests may need attention. Check what your hosting platform handled automatically.

Rename locally, update the remote when needed, and coordinate with your team.

#git #github #versioncontrol #gitbranch #developer #programming #softwareengineering #devops #rubyonrails #coding #webdevelopment #gitcommands #codingtips #softwaredevelopment #backend

— #Astmation —
#software #systems, #automation, and #AI-powered #applications.
Build. Automate. Evolve.
https://astmation.com/


Watch on YouTube

Back to videos