Deleting branches is important to ensure old code doesn't hang around or the wrong thing doesn't get merged
Note: In the examples below pow
will be used for the branch name
Delete a local branch
If you have a local branch you want to delete you can run
git branch -d pow
If your branch has not been merged into your current branch you need to change the -d
to a capital:
git branch -D pow
Delete a remote branch
If you wish to delete the branch via command line, you have to "push" it with a colon (:
) preceding the name
git push origin :pow
Updating your local branch data
If you deleted your remote branch from another computer (or via the website if on Github/Gitlab), you might find it is still listed when running a git branch -a
. This means your local Git repository thinks the branch still exits and could cause conflicts if you try to create a branch of the same name.
To remove these, you can fetch with an additional --prune
parameter
git fetch origin --prune
Tip: If you want it to always prune when you do a git fetch origin
, you can set this as a global setting:
git config --global fetch.prune true
Read time: 1 mins
Tags: Git
Top comments (0)