Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -851,6 +852,16 @@ Deleted feature/dashboard (was 923befa).
...
```

## git delete-squashed-branches

Deletes branches that have been "squashed-merged" into a specified branch

```bash
$ git delete-squashed-branches main
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also update the doc

Copy link
Contributor Author

@allejo allejo May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sound to you? 6867c79

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also need to update the output of git delete-squashed-branches main?
Would be better if we use $ (branch) git ... to indicate the branch change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Is this a new convention or are there other commands that do this too?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. But I think this way will be more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sound to you?

```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 ...
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty! Amended to my last commit

Deleted branch dependabot/bundler/kramdown-2.3.1 (was 1d3fb00).
Deleted branch dependabot/bundler/rexml-3.2.5 (was a7e4052).
```

## git fresh-branch

Create empty local branch `name`:
Expand Down
17 changes: 17 additions & 0 deletions bin/git-delete-squashed-branches
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

targetBranch=$1

if [[ -z $targetBranch ]]; then
targetBranch=$(git rev-parse --abbrev-ref HEAD)
else
git checkout -q $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
4 changes: 4 additions & 0 deletions etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')"
}
Expand Down
6 changes: 6 additions & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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' \
Expand Down
3 changes: 3 additions & 0 deletions etc/git-extras.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions man/git-delete-squashed-branches.1
Original file line number Diff line number Diff line change
@@ -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 [<target\-branch>]
.
.SH "DESCRIPTION"
Deletes all git branches that have been "squash\-merged" into \fBtarget\-branch\fR\.
.
.SH "OPTIONS"
<target\-branch>
.
.P
The target branch were the "squashed\-merged" branches were committed to\.
.
.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>
124 changes: 124 additions & 0 deletions man/git-delete-squashed-branches.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions man/git-delete-squashed-branches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
git-delete-squashed-branches(1) -- Delete branches that were squashed
=====================================================================

## SYNOPSIS

`git-delete-squashed-branches` [&lt;branch-name&gt;]

## DESCRIPTION

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

## OPTIONS

&lt;branch-name&gt;

The target branch were the "squashed-merged" branches were committed to.

## 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 &lt;<[email protected]>&gt; and Vladimir Jimenez &lt;<[email protected]>&gt;

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
1 change: 1 addition & 0 deletions man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down