So you want to rename a Git branch. Brave choice. This short tutorial walks through renaming a branch locally, publishing the new name to GitHub, and cleaning up the old reference so your CI and teammates do not hate you. It preserves commit history and explains how to handle default branches and open pull requests.
Rename a branch when the name no longer reflects the work, when you fix a typo, or when a new naming convention arrives and your repo suddenly looks too 2017. Renaming a branch does not change commits. It only changes the ref name, so your version control history stays safe.
Either rename the branch you are on or rename a different branch from any checkout. The git-branch command handles the local rename while preserving history.
git branch -m new-branch-name
To rename a branch you are not currently on use this form.
git branch -m old-branch-name new-branch-name
Now publish the new branch name to the remote with git-push. If you want future pulls and pushes to work without extra flags add the upstream in one go.
git push origin new-branch-name
git push -u origin new-branch-name
If the renamed branch was the repository default update the default branch in the repository settings on GitHub. This prevents surprises for automation and collaborators that expect a specific default branch.
Once the new branch exists remotely remove the obsolete name so it does not clutter the branch list or confuse CI.
git push origin --delete old-branch-name
After deleting, check open pull requests and any branch protection rules on GitHub. Make sure protected rules are moved to the new branch name if needed, and verify pull requests still point to the right commits.
Prune stale references and fix any local tracking that still points at the old remote name.
git remote prune origin
git branch -vv
If a local branch still tracks the old remote, point it to the new upstream.
git branch -u origin/new-branch-name local-branch-name
If CI or automation still references the old name check branch protection and workflow files. Some GitHub Actions or scripts may hardcode branch names, so update them. If a pull request seems detached, check the PR on GitHub. Often it will follow the commits, but you might need to retarget the PR or recreate it in rare setups.
Final reassurance, for the fearful and the bold. Renaming is a ref move, not a rewrite. No need to force push or rewrite history. Just rename, publish, delete, and breathe easy while your repo keeps behaving like a repository.
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.