How to Delete a Git Branch Locally and Remotely
Managing Git branches is a critical part of keeping your repository clean and organized. Here’s how you can delete a Git branch both locally and remotely.
Deleting a Branch Locally
To delete a local branch in Git, use the following command:
git branch -d branch-name
This will delete the branch only if it has been merged. If the branch is not merged, use:
git branch -D branch-name
Deleting a Branch Remotely
To delete a remote branch, you can use:
git push origin --delete branch-name
This removes the branch from the remote repository.
Additional Tips
- Always double-check your branch name with
git branch
before deleting. - Ensure your changes are merged or backed up before branch deletion.
Further Learning
For more detailed information, refer to the official Git documentation. You can also explore our Git guides section for related tutorials.