mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Merge branch 'tj:main' into main
This commit is contained in:
commit
91bf8dbaef
16
Commands.md
16
Commands.md
|
|
@ -18,6 +18,7 @@
|
|||
- [`git cp`](#git-cp)
|
||||
- [`git create-branch`](#git-create-branch)
|
||||
- [`git delete-branch`](#git-delete-branch)
|
||||
- [`git delete-gone-branches`](#git-delete-gone-branches)
|
||||
- [`git delete-merged-branches`](#git-delete-merged-branches)
|
||||
- [`git delete-squashed-branches`](#git-delete-squashed-branches)
|
||||
- [`git delete-submodule`](#git-delete-submodule)
|
||||
|
|
@ -932,6 +933,21 @@ Delete local and remote tag `name`:
|
|||
$ git delete-tag 0.0.1
|
||||
```
|
||||
|
||||
## git delete-gone-branches
|
||||
|
||||
Deletes all local branches whose remote-tracking branch has been deleted (i.e. branches shown as `[gone]` in `git branch -vv`). Use `--dry-run` to preview what would be deleted.
|
||||
|
||||
```bash
|
||||
$ git delete-gone-branches
|
||||
Deleted branch feature-123 (was abc1234).
|
||||
Deleted branch feature-456 (was def5678).
|
||||
|
||||
$ git delete-gone-branches --dry-run
|
||||
Would delete the following branches:
|
||||
feature-123
|
||||
feature-456
|
||||
```
|
||||
|
||||
## git delete-merged-branches
|
||||
|
||||
Deletes branches that are listed in `git branch --merged`.
|
||||
|
|
|
|||
60
bin/git-delete-gone-branches
Executable file
60
bin/git-delete-gone-branches
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
dry_run=false
|
||||
force=false
|
||||
prune=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-n|--dry-run)
|
||||
dry_run=true
|
||||
shift
|
||||
;;
|
||||
-f|--force)
|
||||
force=true
|
||||
shift
|
||||
;;
|
||||
-p|--prune)
|
||||
prune=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Usage: git delete-gone-branches [-n|--dry-run] [-f|--force] [-p|--prune]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$prune" = true ]; then
|
||||
git fetch --prune
|
||||
fi
|
||||
|
||||
gone_branches=$(git for-each-ref --format \
|
||||
'%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)' refs/heads/ | sed '/^$/d')
|
||||
|
||||
if [ -z "$gone_branches" ]; then
|
||||
echo "No branches with a gone remote found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$dry_run" = true ]; then
|
||||
echo "Would delete the following branches:"
|
||||
echo "$gone_branches"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "The following branches will be deleted:"
|
||||
echo "$gone_branches"
|
||||
|
||||
if [ "$force" = false ]; then
|
||||
read -r -p "Delete these branches? [y/N] " confirm
|
||||
if [[ ! "$confirm" =~ ^[yY]$ ]]; then
|
||||
echo "Aborted."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$gone_branches" | xargs git branch -D
|
||||
|
|
@ -213,6 +213,11 @@ _git-delete-branch() {
|
|||
__gitex_branch_names_unique
|
||||
}
|
||||
|
||||
_git-delete-gone-branches() {
|
||||
_arguments \
|
||||
'(-n --dry-run)'{-n,--dry-run}'[show branches that would be deleted without deleting]'
|
||||
}
|
||||
|
||||
_git-delete-squashed-branches() {
|
||||
_arguments \
|
||||
':branch-name:__gitex_branch_names'
|
||||
|
|
@ -421,6 +426,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
|
|||
count:'show commit count' \
|
||||
create-branch:'create branches' \
|
||||
delete-branch:'delete branches' \
|
||||
delete-gone-branches:'delete branches whose remote is gone' \
|
||||
delete-merged-branches:'delete merged branches' \
|
||||
delete-squashed-branches:'delete squashed branches' \
|
||||
delete-submodule:'delete submodules' \
|
||||
|
|
|
|||
54
man/git-delete-gone-branches.1
Normal file
54
man/git-delete-gone-branches.1
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "GIT\-DELETE\-GONE\-BRANCHES" "1" "March 2026" "" "Git Extras"
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBgit\-delete\-gone\-branches\fR \- Delete branches whose remote is gone
|
||||
.
|
||||
.SH "SYNOPSIS"
|
||||
\fBgit\-delete\-gone\-branches\fR [\-n|\-\-dry\-run] [\-f|\-\-force] [\-p|\-\-prune]
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
Deletes all local branches whose remote\-tracking branch has been deleted\. This commonly happens after a pull request is merged and the remote branch is removed\. By default, lists the branches and prompts for confirmation before deleting\.
|
||||
.
|
||||
.SH "OPTIONS"
|
||||
\-n, \-\-dry\-run
|
||||
.
|
||||
.P
|
||||
Show the branches that would be deleted without actually deleting them\.
|
||||
.
|
||||
.P
|
||||
\-f, \-\-force
|
||||
.
|
||||
.P
|
||||
Skip the confirmation prompt and delete branches immediately\.
|
||||
.
|
||||
.P
|
||||
\-p, \-\-prune
|
||||
.
|
||||
.P
|
||||
Run \fBgit fetch \-\-prune\fR before checking for gone branches, to ensure remote\-tracking refs are up to date\.
|
||||
.
|
||||
.SH "EXAMPLES"
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git delete\-gone\-branches
|
||||
|
||||
$ git delete\-gone\-branches \-\-dry\-run
|
||||
|
||||
$ git delete\-gone\-branches \-\-force
|
||||
|
||||
$ git delete\-gone\-branches \-\-prune
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.SH "AUTHOR"
|
||||
Written by Utsav Sabharwal <\fIhttps://github\.com/codersofthedark\fR>
|
||||
.
|
||||
.SH "REPORTING BUGS"
|
||||
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
|
||||
.
|
||||
.SH "SEE ALSO"
|
||||
<\fIhttps://github\.com/tj/git\-extras\fR>
|
||||
135
man/git-delete-gone-branches.html
Normal file
135
man/git-delete-gone-branches.html
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
||||
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
|
||||
<title>git-delete-gone-branches(1) - Delete branches whose remote is gone</title>
|
||||
<style type='text/css' media='all'>
|
||||
/* style: man */
|
||||
body#manpage {margin:0}
|
||||
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
|
||||
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
|
||||
.mp h2 {margin:10px 0 0 0}
|
||||
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
|
||||
.mp h3 {margin:0 0 0 4ex}
|
||||
.mp dt {margin:0;clear:left}
|
||||
.mp dt.flush {float:left;width:8ex}
|
||||
.mp dd {margin:0 0 0 9ex}
|
||||
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
|
||||
.mp pre {margin-bottom:20px}
|
||||
.mp pre+h2,.mp pre+h3 {margin-top:22px}
|
||||
.mp h2+pre,.mp h3+pre {margin-top:5px}
|
||||
.mp img {display:block;margin:auto}
|
||||
.mp h1.man-title {display:none}
|
||||
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
|
||||
.mp h2 {font-size:16px;line-height:1.25}
|
||||
.mp h1 {font-size:20px;line-height:2}
|
||||
.mp {text-align:justify;background:#fff}
|
||||
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
|
||||
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
|
||||
.mp u {text-decoration:underline}
|
||||
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
|
||||
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
|
||||
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
|
||||
.mp b.man-ref {font-weight:normal;color:#434241}
|
||||
.mp pre {padding:0 4ex}
|
||||
.mp pre code {font-weight:normal;color:#434241}
|
||||
.mp h2+pre,h3+pre {padding-left:0}
|
||||
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
|
||||
ol.man-decor {width:100%}
|
||||
ol.man-decor li.tl {text-align:left}
|
||||
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
|
||||
ol.man-decor li.tr {text-align:right;float:right}
|
||||
</style>
|
||||
</head>
|
||||
<!--
|
||||
The following styles are deprecated and will be removed at some point:
|
||||
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
|
||||
|
||||
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
|
||||
.man-navigation should be used instead.
|
||||
-->
|
||||
<body id='manpage'>
|
||||
<div class='mp' id='man'>
|
||||
|
||||
<div class='man-navigation' style='display:none'>
|
||||
<a href="#NAME">NAME</a>
|
||||
<a href="#SYNOPSIS">SYNOPSIS</a>
|
||||
<a href="#DESCRIPTION">DESCRIPTION</a>
|
||||
<a href="#OPTIONS">OPTIONS</a>
|
||||
<a href="#EXAMPLES">EXAMPLES</a>
|
||||
<a href="#AUTHOR">AUTHOR</a>
|
||||
<a href="#REPORTING-BUGS">REPORTING BUGS</a>
|
||||
<a href="#SEE-ALSO">SEE ALSO</a>
|
||||
</div>
|
||||
|
||||
<ol class='man-decor man-head man head'>
|
||||
<li class='tl'>git-delete-gone-branches(1)</li>
|
||||
<li class='tc'>Git Extras</li>
|
||||
<li class='tr'>git-delete-gone-branches(1)</li>
|
||||
</ol>
|
||||
|
||||
<h2 id="NAME">NAME</h2>
|
||||
<p class="man-name">
|
||||
<code>git-delete-gone-branches</code> - <span class="man-whatis">Delete branches whose remote is gone</span>
|
||||
</p>
|
||||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-delete-gone-branches</code> [-n|--dry-run] [-f|--force] [-p|--prune]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
<p> Deletes all local branches whose remote-tracking branch has been deleted.
|
||||
This commonly happens after a pull request is merged and the remote branch
|
||||
is removed. By default, lists the branches and prompts for confirmation
|
||||
before deleting.</p>
|
||||
|
||||
<h2 id="OPTIONS">OPTIONS</h2>
|
||||
|
||||
<p> -n, --dry-run</p>
|
||||
|
||||
<p> Show the branches that would be deleted without actually deleting them.</p>
|
||||
|
||||
<p> -f, --force</p>
|
||||
|
||||
<p> Skip the confirmation prompt and delete branches immediately.</p>
|
||||
|
||||
<p> -p, --prune</p>
|
||||
|
||||
<p> Run <code>git fetch --prune</code> before checking for gone branches, to ensure
|
||||
remote-tracking refs are up to date.</p>
|
||||
|
||||
<h2 id="EXAMPLES">EXAMPLES</h2>
|
||||
|
||||
<pre><code>$ git delete-gone-branches
|
||||
|
||||
$ git delete-gone-branches --dry-run
|
||||
|
||||
$ git delete-gone-branches --force
|
||||
|
||||
$ git delete-gone-branches --prune
|
||||
</code></pre>
|
||||
|
||||
<h2 id="AUTHOR">AUTHOR</h2>
|
||||
|
||||
<p>Written by Utsav Sabharwal <<a href="mailto:utsav.sabharwal@sysdig.com" data-bare-link="true">utsav.sabharwal@sysdig.com</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
<p><<a href="https://github.com/tj/git-extras/issues" data-bare-link="true">https://github.com/tj/git-extras/issues</a>></p>
|
||||
|
||||
<h2 id="SEE-ALSO">SEE ALSO</h2>
|
||||
|
||||
<p><<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>></p>
|
||||
|
||||
|
||||
<ol class='man-decor man-foot man foot'>
|
||||
<li class='tl'></li>
|
||||
<li class='tc'>March 2026</li>
|
||||
<li class='tr'>git-delete-gone-branches(1)</li>
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
50
man/git-delete-gone-branches.md
Normal file
50
man/git-delete-gone-branches.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
git-delete-gone-branches(1) -- Delete branches whose remote is gone
|
||||
====================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`git-delete-gone-branches` [-n|--dry-run] [-f|--force] [-p|--prune]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
Deletes all local branches whose remote-tracking branch has been deleted.
|
||||
This commonly happens after a pull request is merged and the remote branch
|
||||
is removed. By default, lists the branches and prompts for confirmation
|
||||
before deleting.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
-n, --dry-run
|
||||
|
||||
Show the branches that would be deleted without actually deleting them.
|
||||
|
||||
-f, --force
|
||||
|
||||
Skip the confirmation prompt and delete branches immediately.
|
||||
|
||||
-p, --prune
|
||||
|
||||
Run `git fetch --prune` before checking for gone branches, to ensure
|
||||
remote-tracking refs are up to date.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
$ git delete-gone-branches
|
||||
|
||||
$ git delete-gone-branches --dry-run
|
||||
|
||||
$ git delete-gone-branches --force
|
||||
|
||||
$ git delete-gone-branches --prune
|
||||
|
||||
## AUTHOR
|
||||
|
||||
Written by Utsav Sabharwal <<https://github.com/codersofthedark>>
|
||||
|
||||
## REPORTING BUGS
|
||||
|
||||
<<https://github.com/tj/git-extras/issues>>
|
||||
|
||||
## SEE ALSO
|
||||
|
||||
<<https://github.com/tj/git-extras>>
|
||||
|
|
@ -46,6 +46,7 @@ git-extras(1) -- Awesome GIT utilities
|
|||
- **git-cp(1)** Copy a file keeping its history
|
||||
- **git-create-branch(1)** Create branches
|
||||
- **git-delete-branch(1)** Delete branches
|
||||
- **git-delete-gone-branches(1)** Delete branches whose remote is gone
|
||||
- **git-delete-merged-branches(1)** Delete merged branches
|
||||
- **git-delete-squashed-branches(1)** Delete branches that were squashed
|
||||
- **git-delete-submodule(1)** Delete submodules
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ git-count(1) git-count
|
|||
git-cp(1) git-cp
|
||||
git-create-branch(1) git-create-branch
|
||||
git-delete-branch(1) git-delete-branch
|
||||
git-delete-gone-branches(1) git-delete-gone-branches
|
||||
git-delete-merged-branches(1) git-delete-merged-branches
|
||||
git-delete-squashed-branches(1) git-delete-squashed-branches
|
||||
git-delete-submodule(1) git-delete-submodule
|
||||
|
|
|
|||
Loading…
Reference in a new issue