I use a popular Git workflow called feature branching. It starts with creating a new local branch and then pushing it up to the central repository. But once you've finished working on your branch, and you've successfully merged it, how do you delete it?
There are four steps:
- Delete the branch on GitHub
- Delete the local branch
- Delete the reference to the remote branch
- Verify that the branch is gone
1. Delete the branch on GitHub
Once you've successfully merged your pull request, GitHub will give you the option to delete the branch used for the pull request. If you don't do it then, you can still delete the branch at any time after you've merged it.
2. Delete the local branch
my-new-branch with the name of your branch:
git checkout masterto switch back to the
- Then run
git pullso your
masterbranch is up to date with the merge.
- Now run
git branch -d my-new-branchto delete the local branch.
3. Delete the reference to the remote branch
git fetch --prune and you're done! The
--prune flag removes any remote-tracking references that no longer exist on the remote.
4. Verify that the branch is gone
To verify that the branch is truly gone, run
git branch -a. This will show you a list of all branches, local and remote.