I've been working on changing all my repos default branch from master
to main
. Guess
I'm still missing a few, but I've changed most of it.
Since I've been using this so much I decided to write a quick article on how to delete branches both locally and remotely.
To delete a branch locally you can simply run:
git branch -d <name-of-the-branch>
Example:
git branch -d feature/align-button
In case your branch haven't been pushed to the remote origin -d
will not work. In
case you want to force delete a branch use -D
.
To delete a branch remotely is a little different:
git push <remote> --delete <branch>
Example:
git push origin --delete feature/align-button
When you're fetching data from a remote repository use the -p
flag. This will
remove all branches locally that don't exist remotely.
Code:
git fetch -p