How do you delete a branch locally in Git?

How do you delete a branch locally in Git?

a) git branch -d branch-name
b) git remove branch-name
c) git delete branch-name
d) git erase branch-name

Answer:

a) git branch -d branch-name

Explanation:

The git branch -d branch-name command is used to delete a branch locally in Git. It removes the specified branch from your local repository but does not affect any remote branches.

For example, git branch -d feature-branch deletes the feature-branch from your local environment. If you want to force-delete a branch, you can use -D instead of -d.

Deleting branches is important for keeping your repository organized, especially after a feature branch has been merged or is no longer needed.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top