How can I rename any git branch?
Hey Sandhu,
To rename the current branch in Git, you can use the following command: git branch -m
If you want to rename a branch while being on a different branch, you can use: git branch -m
The -m option is short for --move. To push the renamed branch to the remote repository and set the upstream branch: git push origin -u To delete the old remote branch: git push origin --delete If you frequently need to rename branches, you can create a Git alias for the branch -m command: git config --global alias.rename ‘branch -m’ On Windows or other case-insensitive file systems, if the only change is in the capitalization of the branch name, you can use -M instead of -m to force the rename:
git branch -M
Hey Sndhu,
To rename a local Git branch, use the following command:
git branch -m old_branch_name new_branch_name
After renaming the branch locally, you can push the changes to the master branch with:
git push origin new_branch_name:master
This command will push your changes to the master branch on the remote repository. However, your local branch will still be named new_branch_name
.