Free System Design Interview Course
Get Educative's definitive System Design Interview Handbook for free.
While working with Git, it is possible that you come across a situation where you want to delete a remote branch. But before jumping into the intricacies of deleting a remote branch, let’s revisit how you would go about deleting a branch in the local repository with Git.
git branchcommand with
git branchcommand again, this time with the
-d(delete) flag, followed by the name of the branch you want to delete (
testbranch in this case).
Note: Comments are the output produced as a result of running these
git branch -a# *master# test# remote/origin/master# remote/origin/testgit branch -d test# Deleted branch test (was ########).
Note: You can also use the
-Dflag which is synonymous with
--delete --forceinstead of
-d. This will delete the branch regardless of its merge status.
To delete a remote branch, you can’t use the
git branch command. Instead, use the
git push command with
--delete flag, followed by the name of the branch you want to delete. You also need to specify the
remote name (
origin in this case) after
git branch -a# *master# test# remote/origin/master# remote/origin/testgit push origin --delete test# To <URL of your repository>.git# - [deleted] test
Delete this branch:
git push origin --delete JunitTest
git branch -d JunitTest
git push devs --delete JunitTest