How to Rename a Git Branch Both Locally and Remotely? #163286
Answered
by
feedofmri
iAmRubayet1
asked this question in
Programming Help
BodyHey everyone, Guidelines
|
Answered by
feedofmri
Jun 18, 2025
Replies: 1 comment
|
You can rename a branch both locally and remotely with the following steps: I. Rename Locally git branch -m dev-branch main-devThis renames the branch you're currently on. If you're not on git branch -m dev-branch main-devII. Push the Renamed Branch git push origin main-devThen delete the old branch from the remote: git push origin --delete dev-branchIII. Reset the Upstream Tracking git push --set-upstream origin main-devIV. Update Default Branch on GitHub (Optional) |
0 replies
Answer selected by
iAmRubayet1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can rename a branch both locally and remotely with the following steps:
I. Rename Locally
This renames the branch you're currently on. If you're not on
dev-branch, use:II. Push the Renamed Branch
Then delete the old branch from the remote:
III. Reset the Upstream Tracking
IV. Update Default Branch on GitHub (Optional)
If this is a default branch, go to your repository’s Settings > Branches and set
main-devas the new default. Then delete the old one.