Git has no idea who created some branch name, so no, this is not possible in general.
I basically wants to delete all my created branches because they are merged to the parent branch
Branch names do not store parent information either. You can, however, ask whether the tip commit found via some branch name is contained within the set of commits found via some other branch name, using git branch --merged
for instance:
git fetch origin
git branch --merged origin/main
will list out any of your (local) repository branch names that identify a commit that is contained within the commit-set found by origin
's main
(as last updated by git fetch
, hence the git fetch
step first).
William Pursell asks, in a comment:
When you say "delete a branch", do you simply mean that you want to delete the ref, or are you also trying to remove commits?
Your answer is:
To be honest I am not quite sure about the difference of the two.
The difference here is the key, because Git is not really about branches, but rather about commits. If you are going to use Git at all, you must learn about commits. This will also make Git's branching model make some sense. Rather than repeat it all here, though, I'll just refer you to this answer.