How to Rename a Git Branch Both Locally and Remotely? #163286
-
BodyHey everyone, Guidelines
|
Beta Was this translation helpful? Give feedback.
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) |
Beta Was this translation helpful? Give feedback.
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.