diff --git a/Commands.md b/Commands.md index 78fd9ae..d7e8f0f 100644 --- a/Commands.md +++ b/Commands.md @@ -16,6 +16,7 @@ - [`git create-branch`](#git-create-branch) - [`git delete-branch`](#git-delete-branch) - [`git delete-merged-branches`](#git-delete-merged-branches) + - [`git delete-squashed-branches`](#git-delete-squashed-branches) - [`git delete-submodule`](#git-delete-submodule) - [`git delete-tag`](#git-delete-tag) - [`git delta`](#git-delta) @@ -849,6 +850,17 @@ Deleted feature/dashboard (was 923befa). ... ``` +## git delete-squashed-branches + +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. + +```bash +$ (feature-branch) git delete-squashed-branches main +Deleted branch dependabot/bundler/kramdown-2.3.1 (was 1d3fb00). +Deleted branch dependabot/bundler/rexml-3.2.5 (was a7e4052). +$ (main) git ... +``` + ## git fresh-branch Create empty local branch `name`: diff --git a/bin/git-delete-squashed-branches b/bin/git-delete-squashed-branches new file mode 100755 index 0000000..6707da0 --- /dev/null +++ b/bin/git-delete-squashed-branches @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +targetBranch=$1 + +if [[ -z $targetBranch ]]; then + targetBranch=$(git rev-parse --abbrev-ref HEAD) +else + git checkout $targetBranch +fi + +git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do + mergeBase=$(git merge-base $targetBranch $branch) + + if [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]]; then + git branch -D $branch + fi +done diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index 0c6cb00..1493fdd 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -49,6 +49,10 @@ _git_delete_branch(){ __gitcomp "$(__git_heads)" } +_git_delete_squashed_branches(){ + __gitcomp "$(__git_heads)" +} + _git_delete_submodule(){ __gitcomp "$(git submodule status | awk '{print $2}')" } diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index f21817b..ea7cba9 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -158,6 +158,11 @@ _git-delete-branch() { ':branch-name:__gitex_branch_names' } +_git-delete-squashed-branches() { + _arguments \ + ':branch-name:__gitex_branch_names' +} + _git-delete-submodule() { _arguments \ @@ -347,6 +352,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \ create-branch:'create branches' \ delete-branch:'delete branches' \ delete-merged-branches:'delete merged branches' \ + delete-squashed-branches:'delete squashed branches' \ delete-submodule:'delete submodules' \ delete-tag:'delete tags' \ delta:'lists changed files' \ diff --git a/etc/git-extras.fish b/etc/git-extras.fish index 58e2f19..319bdd6 100644 --- a/etc/git-extras.fish +++ b/etc/git-extras.fish @@ -17,6 +17,7 @@ set __fish_git_extras_commands \ "create-branch:Create branches" \ "delete-branch:Delete branches" \ "delete-merged-branches:Delete merged branches" \ + "delete-squashed-branches:Delete squashed branches" \ "delete-submodule:Delete submodules" \ "delete-tag:Delete tags" \ "delta:Lists changed files" \ @@ -106,6 +107,8 @@ complete -c git -f -n '__fish_git_using_command count' -l all -d 'detailed commi 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' # delete-branch complete -c git -x -n '__fish_git_using_command delete-branch' -a '(__fish_git_branches)' -d 'branch to delete' +# delete-squashed-branches +complete -c git -x -n '__fish_git_using_command delete-squashed-branches' -a '(__fish_git_branches)' -d 'branch to target for squashed merges' # delete-submodule 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' # delete-tag diff --git a/man/git-delete-squashed-branches.1 b/man/git-delete-squashed-branches.1 new file mode 100644 index 0000000..45831b1 --- /dev/null +++ b/man/git-delete-squashed-branches.1 @@ -0,0 +1,54 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "May 2021" "" "Git Extras" +. +.SH "NAME" +\fBgit\-delete\-squashed\-branches\fR \- Delete branches that were squashed +. +.SH "SYNOPSIS" +\fBgit\-delete\-squashed\-branches\fR [] +. +.SH "DESCRIPTION" +Deletes all git branches that have been "squash\-merged" into \fBbranch\-name\fR\. +. +.SH "OPTIONS" + +. +.P +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\. +. +.SH "EXAMPLES" +Delete all branches that were "squash\-merged" into the current checked out branch\. +. +.IP "" 4 +. +.nf + +$ git delete\-squashed\-branches +. +.fi +. +.IP "" 0 +. +.P +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\. +. +.IP "" 4 +. +.nf + +$ git delete\-squashed\-branches main +. +.fi +. +.IP "" 0 +. +.SH "AUTHOR" +Written by Teddy Katz <\fIteddy\.katz@gmail\.com\fR> and Vladimir Jimenez <\fIme@allejo\.io\fR> +. +.SH "REPORTING BUGS" +<\fIhttps://github\.com/tj/git\-extras/issues\fR> +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-delete-squashed-branches.html b/man/git-delete-squashed-branches.html new file mode 100644 index 0000000..a1ab81b --- /dev/null +++ b/man/git-delete-squashed-branches.html @@ -0,0 +1,124 @@ + + + + + + git-delete-squashed-branches(1) - Delete branches that were squashed + + + + +
+ + + +
    +
  1. git-delete-squashed-branches(1)
  2. +
  3. Git Extras
  4. +
  5. git-delete-squashed-branches(1)
  6. +
+ +

NAME

+

+ git-delete-squashed-branches - Delete branches that were squashed +

+ +

SYNOPSIS

+ +

git-delete-squashed-branches [<branch-name>]

+ +

DESCRIPTION

+ +

Deletes all git branches that have been "squash-merged" into branch-name.

+ +

OPTIONS

+ +

<branch-name>

+ +

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.

+ +

EXAMPLES

+ +

Delete all branches that were "squash-merged" into the current checked out branch.

+ +
$ git delete-squashed-branches
+
+ +

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.

+ +
$ git delete-squashed-branches main
+
+ +

AUTHOR

+ +

Written by Teddy Katz <teddy.katz@gmail.com> and Vladimir Jimenez <me@allejo.io>

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. May 2021
  3. +
  4. git-delete-squashed-branches(1)
  5. +
+ +
+ + diff --git a/man/git-delete-squashed-branches.md b/man/git-delete-squashed-branches.md new file mode 100644 index 0000000..e46cd28 --- /dev/null +++ b/man/git-delete-squashed-branches.md @@ -0,0 +1,38 @@ +git-delete-squashed-branches(1) -- Delete branches that were squashed +===================================================================== + +## SYNOPSIS + +`git-delete-squashed-branches` [<branch-name>] + +## DESCRIPTION + +Deletes all git branches that have been "squash-merged" into `branch-name`. + +## OPTIONS + + <branch-name> + + 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. + +## EXAMPLES + + Delete all branches that were "squash-merged" into the current checked out branch. + + $ git delete-squashed-branches + + 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. + + $ git delete-squashed-branches main + +## AUTHOR + +Written by Teddy Katz <> and Vladimir Jimenez <> + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> diff --git a/man/git-extras.md b/man/git-extras.md index 4a8625a..d9e921b 100644 --- a/man/git-extras.md +++ b/man/git-extras.md @@ -44,6 +44,7 @@ git-extras(1) -- Awesome GIT utilities - **git-create-branch(1)** Create branches - **git-delete-branch(1)** Delete branches - **git-delete-merged-branches(1)** Delete merged branches + - **git-delete-squashed-branches(1)** Delete branches that were squashed - **git-delete-submodule(1)** Delete submodules - **git-delete-tag(1)** Delete tags - **git-delta(1)** Lists changed files diff --git a/man/index.txt b/man/index.txt index 0850a69..fc6f88c 100644 --- a/man/index.txt +++ b/man/index.txt @@ -16,6 +16,7 @@ git-cp(1) git-cp git-create-branch(1) git-create-branch git-delete-branch(1) git-delete-branch 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 git-delete-tag(1) git-delete-tag git-delta(1) git-delta