Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?
Example:
Branches (local and remote)
Locally, I only have a master branch. Now I need to work on bug-fix-a, so I check it out, work on it, and push changes to the remote. Next I do the same with bug-fix-b.
Branches (local and remote)
Now I have local branches master, bug-fix-a, bug-fix-b. The Master branch maintainer will merge my changes into master and delete all branches he has already merged.
So the current state is now:
Branches (local and remote)
Now I would like to call some command to delete branches (in this case bug-fix-a, bug-fix-b), which are no longer represented in the remote repository.
It would be something like the existing command git remote prune origin
, but more like git local prune origin
.
git remote prune origin
prunes tracking branches not on the remote.
git branch --merged
lists branches that have been merged into the current branch.
xargs git branch -d
deletes branches listed on standard input.
Be careful deleting branches listed by git branch --merged
. The list could include master
or other branches you'd prefer not to delete.
To give yourself the opportunity to edit the list before deleting branches, you could do the following in one line:
git branch --merged >/tmp/merged-branches && \
vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
Answered 2023-09-20 20:56:21
* master
on my system. The following command worked for me: git branch -d $(git branch --merged |tail -n +2)
- anyone develop
then git branch --merged
includes master
! You probably (definitely!) don't want to delete that. Also I think it should be git branch -d
where lowercase -d
means "safe delete" e.g. only delete if merged. - anyone git branch --merged | grep -v "master" >/tmp/merged-branches && vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches
- anyone The safest way to do this is to use the "plumbing" command git for-each-ref
with the interpolation variable %(upstream:track)
, which will be [gone]
when the branch is no longer on the remote:
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done
This approach is somewhat safer than using the "porcelain" command, because there is no risk of accidentally matching on part of the commit message. Here is a version using the "porcelain" git commands:
git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done
The way this works is that after the command
git fetch -p
removes the remote references, when you run
git branch -vv
it will show 'gone' as the remote status. For example,
$ git branch -vv
master b900de9 [origin/master: behind 4] Fixed bug
release/v3.8 fdd2f4e [origin/release/v3.8: behind 2] Fixed bug
release/v3.9 0d680d0 [origin/release/v3.9: behind 2] Updated comments
bug/1234 57379e4 [origin/bug/1234: gone] Fixed bug
This is what the scripts iterate over.
Answered 2023-09-20 20:56:21
git branch -vv | gawk '{print $1,$4}' | grep 'gone]' | gawk '{print $1}'
- anyone awk '/: gone]/{if ($1!="*") print $1}'
. This now works as expected. - anyone test = "!git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done"
- anyone Most of these answers do not actually answer the original question. I did a bunch of digging and this was the cleanest solution I found. Here is a slightly more thorough version of that answer:
git checkout master
git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d
Explanation:
Works by pruning your tracking branches then deleting the local ones that show they are "gone" in git branch -vv
.
Notes:
If your language is set to something other than English you will need to change gone
to the appropriate word. Branches that are local only will not be touched. Branches that have been deleted on remote but were not merged will show a notification but not be deleted on local. If you want to delete those as well change -d
to -D
.
Answered 2023-09-20 20:56:21
git checkout master && ...
at the beginning of the command. - anyone git branch -vv
will start with an asterisk which will in the end result in executing git branch -d *
. Here is a patched version which will ignore lines with asterisk: git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d
- anyone I wouldn't normally answer a question that already has 16 answers, but all the other answers are wrong, and the right answer is so simple. The question says, "Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?"
If "simple" means deleting them all in one go, not fragile, not dangerous, and without reliance on tools that not all readers will have, then the right answer is: no.
Some answers are simple, but they don't do what was asked. Others do what was asked, but are not simple: all rely on parsing Git output through text-manipulation commands or scripting languages, which may not be present on every system. On top of that, most of the suggestions use porcelain commands, whose output is not designed to be parsed by script ("porcelain" refers to the commands intended for human operation; scripts should use the lower-level "plumbing" commands).
Further reading:
git branch
output in a script.git remote prune
, git prune
, git fetch --prune
If you want to do this safely, for the use case in the question (garbage-collect tracking branches which have been deleted on the server but still exist as local branches) and with high-level Git commands only, you have to
git fetch --prune
(or git fetch -p
, which is an alias, or git remote prune origin
which does the same thing without fetching, and is probably not what you want most of the time).git branch -v
(any orphaned tracking branch will be marked "[gone]").git branch -d [branch_name]
on each orphaned tracking branch(which is what some of the other answers propose).
If you want to script a solution, then for-each-ref
is your starting point, as in Mark Longair's answer here and this answer to another question, but I can't see a way to exploit it without writing a shell script loop, or using xargs or something.
To understand what's happening, you need to appreciate that, in the situation of tracking branches, you have not one branch, but three. (And recall that "branch" means simply a pointer to a commit.)
Given a tracking branch feature/X
, the remote repository (server) will have this branch and call it feature/X
. Your local repository has a branch remotes/origin/feature/X
which means, "This is what the remote told me its feature/X branch was, last time we talked," and finally, the local repository has a branch feature/X
which points to your latest commit, and is configured to "track" remotes/origin/feature/X
, meaning that you can pull and push to keep them aligned.
At some point, someone has deleted the feature/X
on the remote. From that moment, you are left with your local feature/X
(which you probably don't want any more, since work on feature X is presumably finished), and your remotes/origin/feature/X
which is certainly useless because its only purpose was to remember the state of the server's branch.
And Git will let you automatically clean up the redundant remotes/origin/feature/X
-- that's what git fetch --prune
does -- but for some reason, it doesn't let you automatically delete your own feature/X
... even though your feature/X
still contains the orphaned tracking information, so it has the information to identify former tracking branches that have been fully merged. (After all, it can give you the information that lets you do the operation by hand yourself.)
Answered 2023-09-20 20:56:21
xargs
or bash, and they probably aren't here looking for a micro-coding challenge, so much as a quick answer they can apply safely without distracting themselves further from their real goal. - anyone For Microsoft Windows Powershell:
git checkout master; git remote update origin --prune; git branch -vv | Select-String -Pattern ": gone]" | % { $_.toString().Trim().Split(" ")[0]} | % {git branch -d $_}
git checkout master
switches to the master branch
git remote update origin --prune
prunes remote branches
git branch -vv
gets a verbose output of all branches (git reference)
Select-String -Pattern ": gone]"
gets only the records where they have been removed from remote.
% { $_.toString().Trim().Split(" ")[0]}
get the branch name
% {git branch -d $_}
deletes the branch
Answered 2023-09-20 20:56:21
.Trim()
after .toString()
in order to remove two spaces before the branch name. - anyone git branch -d
to git branch -D
else I get the error the branch is not fully merged. - anyone git branch -D
is destructive and will delete local work that you have not yet pushed. -d
is always safe, just be careful with -D
. - anyone I found the answer here: How can I delete all git branches which have been merged?
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
You can ensure that master
, or any other branch for that matter, doesn't get removed by adding another grep
after the first one. In that case you would go:
git branch --merged | grep -v "\*" | grep -v "YOUR_BRANCH_TO_KEEP" | xargs -n 1 git branch -d
So if we wanted to keep master
, develop
and staging
for instance, we would go:
git branch --merged | grep -v "\*" | grep -v "master" | grep -v "develop" | grep -v "staging" | xargs -n 1 git branch -d
Since it's a bit long, you might want to add an alias to your .zshrc
or .bashrc
. Mine is called gbpurge
(for git branches purge
):
alias gbpurge='git branch --merged | grep -v "\*" | grep -v "master" | grep -v "develop" | grep -v "staging" | xargs -n 1 git branch -d'
Then reload your .bashrc
or .zshrc
:
. ~/.bashrc
or
. ~/.zshrc
Answered 2023-09-20 20:56:21
Remove ALL local branches that are not on remote
git fetch -p && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
Remove ALL local branches that are not on remote AND that are fully merged AND that are not used as said in many answers before.
git fetch -p && git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d
git fetch -p
will prune all branches no longer existing on remotegit branch -vv
will print local branches and pruned branch will be tagged with gone
grep ': gone]'
selects only branch that are goneawk '{print $1}'
filter the output to display only the name of the branchesxargs git branch -D
will loop over all lines (branches) and force remove this branchWhy git branch -D
and not git branch -d
else you will have for branches that are not fully merged.
error: The branch 'xxx' is not fully merged.
Answered 2023-09-20 20:56:21
You could do this:
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d
P.S.: as pointed out by Sam H.
execute this first:
git remote prune origin
Answered 2023-09-20 20:56:21
git remote prune origin
first? - anyone xargs git branch -D
(capital D) if you want to force a deletion - anyone The pattern matching for "gone" in most of the other solutions was a little scary for me. To be safer, this uses the --format
flag to pull out each branch's upstream tracking status.
I needed a Windows-friendly version, so this deletes all branches that are listed as "gone" using Powershell:
git branch --list --format "%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)" |
? { $_ -ne "" } |
% { git branch -D $_ }
The first line lists the name of local branches whose upstream branch is "gone". The next line removes blank lines (which are output for branches that aren't "gone"), then the branch name is passed to the command to delete the branch.
Answered 2023-09-20 20:56:21
--format
option seems to be fairly new; I needed to upgrade git from 2.10.something to 2.16.3 to get it. This is my modification for Linux-ish systems: git branch --list --format "%(if:equals=[gone])%(upstream:track)%(then)%(refname)%(end)" | sed 's,^refs/heads/,,' | grep . | xargs git branch -D
- anyone refname:short
. Then you can delete the line % { $_ -replace '^refs/heads/', '' }
- anyone git branch --list --format "%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)" | where { $_ -ne "" } | foreach { git branch -d $_ }
Also probably a good idea to use -d
instead of -D
. Force delete should not be necessary for branches that are no longer on remote. - anyone Yet another answer, because none of the solutions suit my needs on elegance and cross-platformness:
Command to delete local branches not on remote:
for b in $(git for-each-ref --format='%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)' refs/heads); do git branch -d $b; done
To integrate it with gitconfig so it can be run with git branch-prune
:
Bash
git config --global alias.branch-prune '!git fetch -p && for b in $(git for-each-ref --format='\''%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)'\'' refs/heads); do git branch -d $b; done'
PowerShell
git config --global alias.branch-prune '!git fetch -p && for b in $(git for-each-ref --format=''%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)'' refs/heads); do git branch -d $b; done'
(Need help in finding a universal command for PowerShell and bash)
git branch-prune
command to your gitgit for-each-ref
--filter
so no external dependencies needed~\.gitconfig
. After executing this you can simply do git branch-prune
Answered 2023-09-20 20:56:21
git branch -d branch-name
command used here will not remove it. It will send a notification that the branch is not merged, and show the command to delete it anyway (which is git branch -D branch-name
) - anyone git fetch -p
This will prune any branches that no longer exist on the remote.
Answered 2023-09-20 20:56:21
X
; you git checkout X
; now your repository has a (local) tracking branch X
and a remote branch origin/X
; the remote repository deletes X
; you git fetch-p
; in your local repository, not only origin/X
but also X
have been deleted. Is that what you're saying? - anyone Remove all branches that have been merged into master, but don't try to remove master itself:
git checkout master && git pull origin master && git fetch -p && git branch -d $(git branch --merged | grep master -v)
or add an alias:
alias gitcleanlocal="git checkout master && git pull origin master && git fetch -p && git branch -d $(git branch --merged | grep master -v)"
Explanation:
git checkout master
checkout master branch
git pull origin master
ensure local branch has all remote changes merged
git fetch -p
remove references to remote branches that have been deleted
git branch -d $(git branch master --merged | grep master -v)
delete all branches that have been merged into master, but don't try to remove master itself
Answered 2023-09-20 20:56:21
git branch -D
command - anyone git branch -d
which should issue a warning about not pushed branches. - anyone While the above answers cover how to prune branches manually, this answer adds automation to solve this. git
now has a new setting to prune stale branches that are no longer on the remote for every fetch action. This is great because we no longer have to manually call remote prune
every time we delete branches (git pull
also calls git fetch
).
To enable this in the global config:
git config --global fetch.prune true
Making the thing happen automatically means you can forget to add this setting on new machines. It just works.
git config --global remote.<name>.prune true
We can apply the same command for local pruning as well without the --global
flag.
The commands above apply to the global and local .gitconfig
as follows:
...
[fetch]
prune = true
I can recommend adding this to an ansible configuration or to your dotfiles repository (.gitconfig
) to automate the setup for the future.
The configuration setting calls the below command on every fetch:
git remote prune <remote name>
To prune references as part of your normal workflow without needing to remember to run that, set fetch.prune
globally or remote.<name>.prune
per-remote in the config. See git-config.
Answered 2023-09-20 20:56:21
git fetch
+ git pull
. The branch still exists on my local. - anyone Yet-another-answer for the pile, drawing heavily from Patrick's answer (which I like because it seems to do away with any ambiguity about where gone]
will match in the git branch
output) but adding a *nix bent.
In its simplest form:
git branch --list --format \
"%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)" \
| xargs git branch -D
I have this wrapped up in a git-gone
script on my path:
#!/usr/bin/env bash
action() {
${DELETE} && xargs git branch -D || cat
}
get_gone() {
git branch --list --format \
"%(if:equals=[gone])%(upstream:track)%(then)%(refname:short)%(end)"
}
main() {
DELETE=false
while [ $# -gt 0 ] ; do
case "${1}" in
(-[dD] | --delete) DELETE=true ;;
esac
shift
done
get_gone | action
}
main "${@}"
NB - The --format
option seems to be fairly new; I needed to upgrade git from 2.10.something to 2.16.3 to get it.
EDIT: tweaked to include suggestion about refname:short
from Benjamin W.
NB2 - I've only tested in bash
, hence the hashbang, but probably portable to sh
.
Answered 2023-09-20 20:56:21
sed
part by using %(refname:short)
in the first line? - anyone --format
. Another way to skip the sed
part is to use git update-ref -d
. Note that this is probably somewhat unsafe, using git for-each-ref
is safer here (given --shell
). - anyone --format
to do this myself. Just one question: why the #!bash
? Everything here looks like portable sh
to me. - anyone This will delete all the merged local branched except local master reference and the one currently being used:
git branch --merged | grep -v "*" | grep -v "master" | xargs git branch -d
And this will delete all the branches having already been removed from the remote repository referenced by "origin", but are still locally available in "remotes/origin".
git remote prune origin
Answered 2023-09-20 20:56:21
git branch -vv | grep 'gone]' | grep -v "\*" | awk '{print $1}' | xargs -r git branch -d
Explanation: I prefer replacing the git branch --merged
by git branch -vv
to show the status (gone) because the previous git branch --merged
can show also the master - anyone I don't think there is a built-in command to do this, but it is safe to do the following:
git checkout master
git branch -d bug-fix-a
When you use -d
, git will refuse to delete the branch unless it is completely merged into HEAD
or its upstream remote-tracking branch. So, you could always loop over the output of git for-each-ref
and try to delete each branch. The problem with that approach is that I suspect that you probably don't want bug-fix-d
to be deleted just because origin/bug-fix-d
contains its history. Instead, you could create a script something like the following:
#!/bin/sh
git checkout master &&
for r in $(git for-each-ref refs/heads --format='%(refname:short)')
do
if [ x$(git merge-base master "$r") = x$(git rev-parse --verify "$r") ]
then
if [ "$r" != "master" ]
then
git branch -d "$r"
fi
fi
done
Warning: I haven't tested this script - use only with care...
Answered 2023-09-20 20:56:21
You can use this:
git fetch --prune
then
git branch -vv | egrep -v "([origin/[a-zA-Z0-9/_-]+])" | awk "{print $1}" | xargs git branch -D
It removes all the local branches that are not linked to the remote
and I personally added an alias that does it for me 🙃
alias gbs='git fetch --prune; git branch -vv | egrep -v "(\[origin\/[a-zA-Z0-9/_-]+\])" | awk "{print \$1}" | xargs git branch -D'
Answered 2023-09-20 20:56:21
Might be useful to some, simple one line to clear all local branches except master and develop
git branch | grep -v "master" | grep -v "develop" | xargs git branch -D
Answered 2023-09-20 20:56:21
'git branch | grep -v "master" | grep -v "develop"
kind of stuff before committing to adding on the deletion part of the command. 👏😊 - anyone Because some answers don’t prevent accidental deletion
git fetch -p && LANG=c git branch -vv | awk '/: gone]/&&!/^\*/{print $1}' | xargs git branch -d
filtering out the branch having *
in the first column is important.
Answered 2023-09-20 20:56:21
LANG=c
so that it also works on non-english environments. - anyone -vv
and filter out the first column. Without the -vv
you only get one column to start with. - anyone : gone]
– but you are right: a single -v
would suffice. - anyone /^*/
won't work. the * is meaningful and has to be escaped: /^\*/
- anyone None of this was really right for me. I wanted something that would purge all local branches that were tracking a remote branch, on origin
, where the remote branch has been deleted (gone
). I did not want to delete local branches that were never set up to track a remote branch (i.e.: my local dev branches). Also I wanted a simple one-liner that just uses git
, or other simple CLI tools, rather than writing custom scripts. I ended up using a bit of grep
and awk
to make this simple command.
This is ultimately what ended up in my ~/.gitconfig
:
[alias]
prune-branches = !git remote prune origin && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs -r git branch -D
Here is a git config --global ...
command for easily adding this as git prune-branches
:
git config --global alias.prune-branches '!git remote prune origin && git branch -vv | grep '"'"': gone]'"'"' | awk '"'"'{print $1}'"'"' | xargs -r git branch -d'
NOTE: In the config command, I use the -d
option to git branch
rather than -D
, as I do in my actual config. I use -D
because I don't want to hear Git complain about unmerged branches. You may want this functionality as well. If so, simply use -D
instead of -d
at the end of that config command.
Answered 2023-09-20 20:56:21
git branch -vv
and greping for : gone]
and not do git branch -v
and grep for [gone]
? - anyone v
. If git branch -v | grep '[gone]'
works for you, go for it. It does seem a little cleaner. - anyone Powershell-based solution that I find more legible than many of the implementations here.
# prune deleted remoted branches
git fetch -p
# get all branches and their corresponding remote status
# deleted remotes will be marked [gone]
git branch -v |
#find ones marked [gone], capture branchName
select-string -Pattern '^ (?<branchName>\S+)\s+\w+ \[gone\]' |
foreach-object{
#delete the captured branchname.
git branch -D $_.Matches[0].Groups['branchName']
}
Answered 2023-09-20 20:56:21
grep gone <(git branch -v) | cut -d ' ' -f 3 | xargs git branch -d
The above command can be used to fetch branches which are merged and deleted in remote and it deletes the local branch which no longer available in remote
Answered 2023-09-20 20:56:21
grep gone <(git branch -v) | cut -d ' ' -f 3 | xargs git branch -D
to force delete all - anyone gone
anywhere in them (e.g. usingonefunction
). - anyone grep -F '[gone]'
of course, to avoid the [
being expanded by shell or used as a character class by grep. - anyone Based on info above, this worked for me:
git br -d `git br -vv | grep ': gone] ' | awk '{print $1}' | xargs`
It removes all local branches with are ': gone] '
on remote.
Answered 2023-09-20 20:56:21
gone
anywhere in its name. - anyone Drawing heavily from a number of other answers here, I've ended up with the following (git 2.13 and above only, I believe), which should work on any UNIX-like shell:
git for-each-ref --shell --format='ref=%(if:equals=[gone])%(upstream:track)%(then)%(refname)%(end)' refs/heads | while read entry; do eval "$entry"; [ ! -z "$ref" ] && git update-ref -d "$ref" && echo "deleted $ref"; done
This notably uses for-each-ref
instead of branch
(as branch
is a "porcelain" command designed for human-readable output, not machine-processing) and uses its --shell
argument to get properly escaped output (this allows us to not worry about any character in the ref name).
Answered 2023-09-20 20:56:21
[ ! -z "$ref" ]
means. I think a multi liner would have helped already. But still thanks for your input! - anyone Based on Git Tip: Deleting Old Local Branches, which looks similar to jason.rickman's solution I implemented a custom command for this purpose called git gone using Bash:
$ git gone
usage: git gone [-pndD] [<branch>=origin]
OPTIONS
-p prune remote branch
-n dry run: list the gone branches
-d delete the gone branches
-D delete the gone branches forcefully
EXAMPLES
git gone -pn prune and dry run
git gone -d delete the gone branches
git gone -pn
combines the pruning and listing the "gone" branches:
$ git gone -pn
bport/fix-server-broadcast b472d5d2b [origin/bport/fix-server-broadcast: gone] Bump modules
fport/rangepos 45c857d15 [origin/fport/rangepos: gone] Bump modules
Then you can pull the trigger using git gone -d
or git gone -D
.
"$BRANCH/.*: gone]"
where $BRANCH
would normally be origin
. This probably won't work if your Git output is localized to French etc.Answered 2023-09-20 20:56:21
git gone
looks like an alias for git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d
, which solves the OP's issue. - anyone for-each-ref
- anyone I like using pipes because it makes the command easier to read.
This is my solution if you would like to remove all branches except master.
git branch | grep -v master | xargs -n 1 git branch -D
To delete other branches that match your criteria, modify the first and second block.
git branch --merged | grep feature_name | xargs -n 1 git branch -D
Answered 2023-09-20 20:56:21
git branch --merged | grep -vE 'main|master|\\*' | xargs -n 1 git branch -D"
- anyone May be this command is what you want.
After run:
git remote prune origin
then run:
diff <(git branch | sed -e 's/*/ /g') <(git branch -r | sed -e 's/origin\///g') | grep '^<'
this will show all branch which not in (git branch -r) but in (git branch)
This method have a problem, it will also show the branch in local which have not pushed before
Answered 2023-09-20 20:56:21
show_deleted = "diff <(git branch | sed -e 's/*/ /g') <(git branch -r | sed -e 's/origin\///g') | grep '^<'"
but it throwing error. - anyone A simpler solution for Windows or others who don't want to/can't script the command line or who don't want to bother with PowerShell.
Dump the branch list into a file
git branch > branches.txt
(or git branch --merged > branches.txt
, if you're the belt and suspenders type;
git branch -d
will protect against deleting unmerged branches)
Open that file in your editor and combine all the lines (I used sublime text, so highlight all and press ctrl+j
)
Add git branch -d
ahead of your branch list.
Select all, copy, and paste (right click in windows cmd window) into the command line.
Answered 2023-09-20 20:56:21
List all local branches who's remote branch is now gone
#!/bin/sh
LC_ALL=C git for-each-ref --format='%(refname:short) %(upstream:track)' refs/heads/ |\
sed -n '/ *\[gone\].*$/{s@@@;p}'
and then pipe that into xargs git branch -D
or -d
.
This solution should be POSIX compatible. No shell specific stuff and POSIX compliant sed
/xargs
only.
LC_ALL=C
makes the script language neutral by forcing englishfor-each-ref
use plumbing command--format='%(refname:short) %(upstream:track)
output branch name
tracking informationrefs/heads
only local branchessed -n '/ *\[gone\].*$/
match the tracking information [gone]
which is not part of a valid branch name so no need to worry about that
{s@@@;p}
delete that tracking part and only print those linesnb: branches cannot contain whitespace so we don't need to do any sanitation for xargs
.
Answered 2023-09-20 20:56:21
The real challenge is when the maintainer squashes the commits. Then, the solutions using git built-in functionality such as --merged
does not help.
The tool git-delete-merged-branches allows for a convenient deletion of branches. I especially like the interactive mode.
Installation (requires python3
):
pip install git-delete-merged-branches
Then execute
git-delete-merged-branches --effort=3
--effort=3
is important to enable deletion of squashed branches.
npx @teppeis/git-delete-squashed
. Supports main
branch.main
branch. @teppeis/git-delete-squashed is based on this.Answered 2023-09-20 20:56:21