Yes you can delete branches. No you should not do it while on the branch unless you enjoy confusing error messages. This guide walks through a safe, clean way to remove a local branch and its counterpart on the remote repository so your teammates stop asking what that weird feature branch was about.
Switch to a stable branch before you try to remove the target. Deleting a branch you are currently on will either fail or make Git sulk loudly.
git switch main
# or
git checkout main
Pick your temperament. The polite delete refuses to remove a branch that still has unmerged work. The rude delete forces removal whether Git likes it or not.
git branch -d branch-name
git branch -D branch-name
If you want to double check that the branch is merged into your mainline run
git branch --merged
Only delete if your branch shows up in that list unless you have a very good reason.
Pushing a delete request removes the branch reference on the remote like origin or github. This is the part that stops the branch from showing up for other developers.
git push origin --delete branch-name
Fetch with pruning to remove stale remote references from your local clone. Then inspect all refs to confirm the branch is gone.
git fetch --prune
git branch -a
git fetch --prune
again if local metadata is staleMove off the branch then delete locally with git branch -d
or -D
if you are forcing it. Push the delete with git push origin --delete branch-name
and finish with git fetch --prune
and git branch -a
to verify. Be careful and set up protections so future you does not get blamed for chaos.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.