No matter which strategy you follow with version control, whether it be gitflow or some custom branching scheme, you will eventually need to remove branches from your Git repositories.
Remove Local Branches
To remove a branch from your local Git repository you the
git branch command with the
git branch -D <branch-name>
For example, to delete a branch with the name
feature/user-profile, you would run the following command:
git branch -D feature/user-profile
If the branch was deleted successfully, the output of the command will show the name of the deleted branch and it’s highest commit ID.
Deleted branch feature/user-profile (was 87beaa4)
git branch -D command only applies to local repositories. A different method is required for deleting remote branches from repositories.
Remove Remote Branches
git branch -D command does not remove a branch from your local repository and any remote repositories. In order to delete a remote repository you must perform a
git push with the
git push --delete <remote> <branch-name>
For example, if your remote repository is named
origin and the branch you would like to delete is named
feature/password-reset-form, you will execute the following command.
git push --delete origin feature/password-reset-form
Which will output the following, if the branch is successfully deleted.
remote: This repository moved. Please use the new location: remote: https://github.com/cloudyyuts/demo-app.git To https://github.com/cloudytuts/demo-app.git - [deleted] feature/password-reset-form