1

I have an unmerged feature branch created more than a year, the feature was never finished. I want to delete that branch and the commits in it.

How can I delete the branch and the commits, the commits aren't useful anymore; I don't want to preserve those commits.

5
  • git branch -d <branch_name>? Apr 3, 2019 at 19:52
  • 1
    And that's it? The commits will be gone? I want to permanently delete those commits
    – ceochronos
    Apr 3, 2019 at 19:53
  • More details here Apr 3, 2019 at 19:55
  • git branch -d <branch_name> doesn't remove those commits. It just deletes the branch and gets them out of your way. I would say you probably don't want to remove the commits completely, it will only potentially harm you in the future if you do. Best practice in git is to not change the history, when you don't have to.
    – Davey
    Apr 11, 2019 at 13:51
  • Late followup, but you are overthinking this @Davey. By running git branch -D [branch] the branch and commits are effectively gone from a practical daily usage perspective. Unless you know how to explore local git files to dig up the old commits, it doesn’t exist locally. And the only real risk comes from the branch being pushed remotely. And in a case like that just run this command git push origin :[branch] to delete the remote branch. And if you truly want to nuke local-only commits after a git push? Delete the local repo copy and do a fresh git pull of the repo. Mar 14, 2023 at 18:46

1 Answer 1

2

Go to another branch, then just type in:

git branch -D [branch]

The lowercase -d means delete but the -D means “Force a delete no matter what.” Then—if you have pushed the branch to a remote origin, just type in this; note the : before the branch name:

git push origin :[branch]

And that : means “Delete the remote branch named [branch].” All done. No trace. All good!

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .