To rename a local Git branch, you can use the git branch command with the -m option followed by the new branch name and the current branch name.
Here are the steps to rename a local Git branch:
Make sure you are on the branch that you want to rename. You can check the current branch using the git branch command.
git branch
Rename the branch using the git branch -m command. For example, to rename the current branch from old_branch to new_branch, run:
git branch -m new_branch
Alternatively, you can specify the old branch name and the new branch name explicitly:
git branch -m old_branch new_branch
If you have already pushed the old branch to a remote repository, you need to push the new branch to the remote repository and delete the old branch.
To push the new branch to the remote repository, use the git push command with the --set-upstream option:
git push --set-upstream origin new_branch
This will set the upstream branch for the new branch and push it to the remote repository.
To delete the old branch from the remote repository, use the git push command with the --delete option:
git push --delete origin old_branch
This will delete the old branch from the remote repository.
Note that renaming a branch can cause problems if other team members are working on the same branch. Make sure to communicate with your team before renaming a branch.
Comments (0)