Renaming a branch is mostly administrative surgery on pointers. The commits stay where they are and history is intact. The real risk is confusion and broken automation when some poor bot or coworker still thinks the old name is sacred. This guide walks you through the safe sequence so you do not leave ghosts in the repo.
Run these commands to avoid surprises
git status
git branch -v
If git status shows dirty changes stash or commit them first. A clean tree makes renames boring and safe.
If you are currently on the branch use the shorter form
git branch -m new-name
If you are on a different branch or want to be explicit use the long form
git branch -m old-name new-name
This only changes the local pointer. Commit history does not move. Nobody needs therapy.
Push the new branch to the remote. You can set upstream in one command so future push and pull are normal
git push -u origin new-name
If you prefer two steps run git push origin new-name first and then git push -u origin new-name to set tracking. If the push fails check permissions and remote branch protection rules.
Once the new branch is safely on the remote delete the old pointer so the branch list is not full of fossils
git push origin --delete old-name
You can also remove the old branch from the hosting web UI if you prefer clicking instead of typing. Either way remove the stale reference so other people do not keep opening PRs against a dead name.
Let collaborators fetch and prune so local lists match the server
git fetch --prune
# or to be thorough
git fetch --all --prune
Advise anyone who had the old branch checked out to either rename their local branch or check out the new one. For example
git checkout new-name
# or to rename a local copy
git branch -m old-name new-name
Update CI configuration, open pull requests and any scripts that referenced the old branch name. If a PR was open update its source branch on the hosting site if needed.
# verify
git status
git branch -v
# rename locally when on the branch
git branch -m new-name
# rename from another branch
git branch -m old-name new-name
# push and set upstream
git push -u origin new-name
# delete old remote branch
git push origin --delete old-name
# have everyone clean up
git fetch --prune
Rename operations are boring when done in the right order and painful when done in a hurry. Follow this sequence, announce the change, and your repo will stay tidy and slightly less haunted.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.