How to delete local and remote Git branches
Delete a local and remote Git branch
To delete both a local and remote Git branch, even if the Git branch has the same name locally and remotely, two commands must be issued:
- A git push origin delete command deletes the remote Git branch
- A git branch delete command deletes the local Git branch
When these two commands are issued, three important Git branch related resources are deleted:
- The remote Git branch is deleted
- The local Git branch is deleted
- The Git repo’s remote tracking branch is deleted
Delete a remote Git branch
It’s not a git branch command that deletes a remote Git branch.
Instead, this happens via the git push command, along with a delete switch and the name of the remote branch to delete.
Remove a remote Git branch example
For example, to delete a remote Git branch named alpha, you would issue the following command:
git@DELETE /c/local/remote/branch (main) git push origin --delete alpha * [deleted] alpha Remote Git branch delete alpha successful
After you issue this command, inspect the remote repository and you would see the removal of the remote Git branch in question.
This command also removes all remote tracking branches that point to the associated branch in the remote repo.
Delete a local Git branch
The deletion of a local Git branch is relatively straightforward.
To delete a local Git branch, simply use the git branch command with the –delete switch and reference the name of the local Git branch to remove.
Remove a local Git branch example
For example, to delete a local Git branch named alpha, the command is as follows:
git@DELETE /c/local/remote/branch (main) git branch --delete alpha Deleted local Git branch alpha (was 4d2cd72)
Confirm Git branch deletion
To confirm the deletion of the local branch, simply issue a git branch -a command. This lists all local Git branches and all remote Git tracking branches.
git@DELETE /c/local/remote/branch (main) git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/main
No reference to the deleted local branch, remote tracking branch or the deleted remote Git branch should remain.
Cameron McKenzie is an AWS Certified AI Practitioner, Machine Learning Engineer, Solutions Architect and author of many popular books in the software development and Cloud Computing space. His growing YouTube channel training devs in Java, Spring, AI and ML has well over 30,000 subscribers.
Next Steps

The AWS Solutions Architect Book of Exam Questions by Cameron McKenzie
So what’s next? A great way to secure your employment or even open the door to new opportunities is to get certified. If you’re interested in AWS products, here are a few great resources to help you get Cloud Practitioner, Solution Architect, Machine Learning and DevOps certified from AWS:
- AWS Certified Cloud Practitioner Book of Exam Questions
- AWS Certified Developer Associate Book of Exam Questions
- AWS Certified AI Practitioner Book of Exam Questions & Answers
- AWS Certified Machine Learning Associate Book of Exam Questions
- AWS Certified DevOps Professional Book of Exam Questions
- AWS Certified Data Engineer Associate Book of Exam Questions
- AWS Certified Solutions Architect Associate Book of Exam Questions
Put your career on overdrive and get AWS certified today!