To change a Git branch name, you first rename the branch locally using git branch -m and then update the remote repository.
Renaming a Local Branch
You can rename a local branch in one of two ways:
- If you are on the branch you want to rename:For example:
git branch -m feature/new-login. - If you are on a different branch:For example:
git branch -m feature/old-login feature/new-login.
Renaming a Remote Branch
Renaming a branch that has already been pushed to a remote repository (like GitHub or GitLab) requires a few extra steps and team coordination.
- Rename your local branch using one of the methods above.
- Push the newly named local branch to the remote repository. This effectively creates a new branch on the remote.The
-u(or--set-upstream) flag is important as it links your local branch to the new remote branch. - Delete the old branch from the remote repository to avoid confusion:
- Update settings on your Git host (e.g., GitHub, GitLab, Bitbucket) if the renamed branch was the default branch or if there were branch protection rules, CI/CD pipelines, or open pull requests associated with the old name.
No comments:
Post a Comment