Delete a Git Branch
To delete a branch locally without pushing it to the remote repository, use the following command:
git branch -d <branch-name>
Replace <branch-name>
with the name of the branch you want to delete. If the branch has not been merged, you might need to use -D
instead of -d
to force the deletion.
To delete a branch from the remote repository (GitHub, GitLab, Bitbucket, etc.), use the following command:
git push origin --delete <branch-name>
Again, replace <branch-name>
with the name of the branch you want to delete.
It is important to note that if you delete a branch, all the commits associated with that branch will also be deleted. Make sure you have pushed the changes you want to keep or have them saved somewhere before deleting the branch.