How do I delete a Git branch locally and remotely?

How do I delete a Git branch locally and remotely?

To delete a Git branch both locally and remotely, you can use the following commands:

Delete Remote Branch:

git push <remote_name> --delete <branch_name>

This command removes the specified branch from the remote repository.

Delete Local Branch:

git branch -d <branch_name>

I remember when I first started working with Git, managing branches was a bit tricky, but these commands have made it much easier. Hope this helps you keep your repositories clean and organized!

To delete a Git branch both locally and remotely, you can use the following commands:

Delete Remote Branch:

git push <remote_name> --delete <branch_name>

This command removes the specified branch from the remote repository.

Delete Local Branch:

git branch -d <branch_name>

I remember when I first started working with Git, managing branches was a bit tricky, but these commands have made it much easier. Hope this helps you keep your repositories clean and organized!

To delete a remote branch, you can use one of the following commands, depending on your Git version:

For Git version 1.7.0 or newer:

git push origin --delete <branch>
git push origin -d <branch>

For older versions of Git:

git push origin :<branch>

To delete a local branch, you can use:

git branch --delete <branch>
git branch -d <branch> # Shorter version
git branch -D <branch> # Force-delete un-merged branches

To delete a local remote-tracking branch, you can use:

git branch --delete --remotes <remote>/<branch>
git branch -dr <remote>/<branch> # Shorter

To delete multiple obsolete remote-tracking branches, you can use:

git fetch <remote> --prune
git fetch <remote> -p # Shorter

Replace <branch> with the name of the branch you want to delete and <remote> with the name of your remote repository. These commands have been lifesavers in keeping my branches tidy!