If you want to rename a Git branch and avoid a tiny office revolt follow these tidy steps. This guide shows how to rename a branch locally push the new name set tracking and remove the old remote reference so history stays neat and your CI does not throw a tantrum.
Branch renames are low risk but do a quick scan first. Make sure you have committed or stashed changes and that no one else is actively pushing to the branch. If there is an open pull request know how your hosting service handles renamed branches.
If you are on the branch you want to rename use this neat and short command. It renames your current branch in place without rewriting history.
git branch -m new-name
If you are not checked out on the branch give both names. This lets you rename from anywhere in the repo.
git branch -m old-name new-name
Send the freshly named branch up to the remote so the remote repo has the new label. This does not remove the old name remotely yet.
git push origin new-name
Tell your local branch which remote branch to follow so git push and git pull behave like adults.
git push --set-upstream origin new-name
Now that the new name is on the remote remove the outdated label so other developers do not get confused by ghost branches.
git push --delete origin old-name
Prune stale references in your local copy so git fetch shows a tidy view. Then send a brief message in your team channel so open pull requests and CI pipelines do not surprise anyone.
git fetch -p
Many hosting services let you update the PR branch to the new name or they will follow the rename automatically. If your provider does not do that manually reassign the PR branch or leave a note so reviewers know what happened. Do not close the PR unless you must.
Follow this order rename locally push the new name set tracking and then delete the old remote name. A quick fetch prune keeps local repos clean and a polite message prevents grown adults from panicking over a new branch name.
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.