How do you rename a Git branch?

How do you rename a Git branch?

a) git rename branch new-name
b) git branch -m old-name new-name
c) git branch new-name
d) git switch branch new-name

Answer:

b) git branch -m old-name new-name

Explanation:

The git branch -m old-name new-name command is used to rename a branch in Git. It changes the name of the branch both locally and remotely if you push the updated branch to the remote repository.

For example, running git branch -m feature-branch awesome-feature will rename feature-branch to awesome-feature.

Renaming branches helps keep your repository organized, especially when the branch name no longer reflects the current work or feature.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top