brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git push origin with delete removes a branch from the server

Git
~/tips/tip-git-push-delete-remote-branch

git push origin --delete feature/login

Deletes a branch on the remote after it has been merged.

git branch -d only deletes the branch on your machine. The copy on the server stays until you delete it there too.

git push origin --delete feature/login

Git asks the remote to delete the branch and confirms with - [deleted] feature/login. You can list several branches in one command. There’s an older syntax that does the same thing, with a colon in front of the name:

git push origin :feature/login

It reads as “push nothing to this branch”. I prefer --delete because nobody has to guess what the colon means.

For the local side, git branch -d feature/login deletes the branch only when it’s merged, and refuses with error: the branch is not fully merged otherwise. -D deletes it anyway.

Other people’s clones keep their origin/feature/login until they fetch with --prune, so the branch can seem to come back in their branch list for a while.

Deleting a remote branch is easy to undo only if someone still has the commits. If the branch held work that wasn’t merged anywhere and nobody else has a copy, it’s gone from the server. Many hosts protect the default branch and release branches against this, but your feature branches usually have no such protection. Run git log origin/main..origin/feature/login first if you’re unsure.

Further reading: git-push documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link