Skip to content

Commit cd8fe4f

Browse files
authored
Merge pull request #924 from allejo/feature/delete-squashed-branches
2 parents 48b2c8f + bebcbd1 commit cd8fe4f

10 files changed

+260
-0
lines changed

Commands.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [`git create-branch`](#git-create-branch)
1717
- [`git delete-branch`](#git-delete-branch)
1818
- [`git delete-merged-branches`](#git-delete-merged-branches)
19+
- [`git delete-squashed-branches`](#git-delete-squashed-branches)
1920
- [`git delete-submodule`](#git-delete-submodule)
2021
- [`git delete-tag`](#git-delete-tag)
2122
- [`git delta`](#git-delta)
@@ -849,6 +850,17 @@ Deleted feature/dashboard (was 923befa).
849850
...
850851
```
851852
853+
## git delete-squashed-branches
854+
855+
Deletes branches that have been "squashed-merged" into a specified branch; this branch will be checked out as a side-effect. If no branch is specified, then it will default to the current checked out branch.
856+
857+
```bash
858+
$ (feature-branch) git delete-squashed-branches main
859+
Deleted branch dependabot/bundler/kramdown-2.3.1 (was 1d3fb00).
860+
Deleted branch dependabot/bundler/rexml-3.2.5 (was a7e4052).
861+
$ (main) git ...
862+
```
863+
852864
## git fresh-branch
853865
854866
Create empty local branch `name`:

bin/git-delete-squashed-branches

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
targetBranch=$1
4+
5+
if [[ -z $targetBranch ]]; then
6+
targetBranch=$(git rev-parse --abbrev-ref HEAD)
7+
else
8+
git checkout $targetBranch
9+
fi
10+
11+
git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do
12+
mergeBase=$(git merge-base $targetBranch $branch)
13+
14+
if [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]]; then
15+
git branch -D $branch
16+
fi
17+
done

etc/bash_completion.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ _git_delete_branch(){
4949
__gitcomp "$(__git_heads)"
5050
}
5151

52+
_git_delete_squashed_branches(){
53+
__gitcomp "$(__git_heads)"
54+
}
55+
5256
_git_delete_submodule(){
5357
__gitcomp "$(git submodule status | awk '{print $2}')"
5458
}

etc/git-extras-completion.zsh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ _git-delete-branch() {
158158
':branch-name:__gitex_branch_names'
159159
}
160160

161+
_git-delete-squashed-branches() {
162+
_arguments \
163+
':branch-name:__gitex_branch_names'
164+
}
165+
161166

162167
_git-delete-submodule() {
163168
_arguments \
@@ -347,6 +352,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
347352
create-branch:'create branches' \
348353
delete-branch:'delete branches' \
349354
delete-merged-branches:'delete merged branches' \
355+
delete-squashed-branches:'delete squashed branches' \
350356
delete-submodule:'delete submodules' \
351357
delete-tag:'delete tags' \
352358
delta:'lists changed files' \

etc/git-extras.fish

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set __fish_git_extras_commands \
1717
"create-branch:Create branches" \
1818
"delete-branch:Delete branches" \
1919
"delete-merged-branches:Delete merged branches" \
20+
"delete-squashed-branches:Delete squashed branches" \
2021
"delete-submodule:Delete submodules" \
2122
"delete-tag:Delete tags" \
2223
"delta:Lists changed files" \
@@ -106,6 +107,8 @@ complete -c git -f -n '__fish_git_using_command count' -l all -d 'detailed commi
106107
complete -c git -x -n '__fish_git_using_command create-branch' -s r -l remote -a '(__fish_git_unique_remote_branches)' -d 'setup remote tracking branch'
107108
# delete-branch
108109
complete -c git -x -n '__fish_git_using_command delete-branch' -a '(__fish_git_branches)' -d 'branch to delete'
110+
# delete-squashed-branches
111+
complete -c git -x -n '__fish_git_using_command delete-squashed-branches' -a '(__fish_git_branches)' -d 'branch to target for squashed merges'
109112
# delete-submodule
110113
complete -c git -x -n "__fish_git_using_command delete-submodule" -a "(__fish_git submodule status 2>/dev/null | string trim | cut -d ' ' -f 2)" -d 'submodule to delete'
111114
# delete-tag

man/git-delete-squashed-branches.1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "May 2021" "" "Git Extras"
5+
.
6+
.SH "NAME"
7+
\fBgit\-delete\-squashed\-branches\fR \- Delete branches that were squashed
8+
.
9+
.SH "SYNOPSIS"
10+
\fBgit\-delete\-squashed\-branches\fR [<branch\-name>]
11+
.
12+
.SH "DESCRIPTION"
13+
Deletes all git branches that have been "squash\-merged" into \fBbranch\-name\fR\.
14+
.
15+
.SH "OPTIONS"
16+
<branch\-name>
17+
.
18+
.P
19+
The target branch were the "squashed\-merged" branches were committed to\. If no value is given, then the current checked out branch will be used\.
20+
.
21+
.SH "EXAMPLES"
22+
Delete all branches that were "squash\-merged" into the current checked out branch\.
23+
.
24+
.IP "" 4
25+
.
26+
.nf
27+
28+
$ git delete\-squashed\-branches
29+
.
30+
.fi
31+
.
32+
.IP "" 0
33+
.
34+
.P
35+
Delete all branches that were "squash\-merged" into the \fBmain\fR branch\. This will checkout the target branch and leave you on said branch after the command has completed\.
36+
.
37+
.IP "" 4
38+
.
39+
.nf
40+
41+
$ git delete\-squashed\-branches main
42+
.
43+
.fi
44+
.
45+
.IP "" 0
46+
.
47+
.SH "AUTHOR"
48+
Written by Teddy Katz <\fIteddy\.katz@gmail\.com\fR> and Vladimir Jimenez <\fIme@allejo\.io\fR>
49+
.
50+
.SH "REPORTING BUGS"
51+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
52+
.
53+
.SH "SEE ALSO"
54+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-delete-squashed-branches.html

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
git-delete-squashed-branches(1) -- Delete branches that were squashed
2+
=====================================================================
3+
4+
## SYNOPSIS
5+
6+
`git-delete-squashed-branches` [&lt;branch-name&gt;]
7+
8+
## DESCRIPTION
9+
10+
Deletes all git branches that have been "squash-merged" into `branch-name`.
11+
12+
## OPTIONS
13+
14+
&lt;branch-name&gt;
15+
16+
The target branch were the "squashed-merged" branches were committed to. If no value is given, then the current checked out branch will be used.
17+
18+
## EXAMPLES
19+
20+
Delete all branches that were "squash-merged" into the current checked out branch.
21+
22+
$ git delete-squashed-branches
23+
24+
Delete all branches that were "squash-merged" into the `main` branch. This will checkout the target branch and leave you on said branch after the command has completed.
25+
26+
$ git delete-squashed-branches main
27+
28+
## AUTHOR
29+
30+
Written by Teddy Katz &lt;<[email protected]>&gt; and Vladimir Jimenez &lt;<[email protected]>&gt;
31+
32+
## REPORTING BUGS
33+
34+
&lt;<https://github.com/tj/git-extras/issues>&gt;
35+
36+
## SEE ALSO
37+
38+
&lt;<https://github.com/tj/git-extras>&gt;

man/git-extras.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ git-extras(1) -- Awesome GIT utilities
4444
- **git-create-branch(1)** Create branches
4545
- **git-delete-branch(1)** Delete branches
4646
- **git-delete-merged-branches(1)** Delete merged branches
47+
- **git-delete-squashed-branches(1)** Delete branches that were squashed
4748
- **git-delete-submodule(1)** Delete submodules
4849
- **git-delete-tag(1)** Delete tags
4950
- **git-delta(1)** Lists changed files

man/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ git-cp(1) git-cp
1616
git-create-branch(1) git-create-branch
1717
git-delete-branch(1) git-delete-branch
1818
git-delete-merged-branches(1) git-delete-merged-branches
19+
git-delete-squashed-branches(1) git-delete-squashed-branches
1920
git-delete-submodule(1) git-delete-submodule
2021
git-delete-tag(1) git-delete-tag
2122
git-delta(1) git-delta

0 commit comments

Comments
 (0)