- Download and unzip gist
- In the unzipped folder, run
sh install.sh - Add the following line to your .zshrc/.bashrc file:
export PATH="$HOME/.git-commands:$PATH"
-
-
Save kevinmbeaulieu/7bedc349a57b8295abbd5d17da17b362 to your computer and use it in GitHub Desktop.
| #!/bin/sh | |
| set -euxo pipefail | |
| git commit --amend --no-edit |
| #!/bin/sh | |
| set -euxo pipefail | |
| git add . | |
| git commit --amend --no-edit |
| #!/bin/sh | |
| set -euo pipefail | |
| verbose=false | |
| for arg in "$@"; do | |
| case "$arg" in | |
| -h | --help) | |
| cat << EOF | |
| Delete branches which have been merged into the default branch" | |
| or which have a name matching the pattern "old/*". | |
| usage: git cleanup [--verbose] | |
| EOF | |
| exit 0 | |
| ;; | |
| -v | --verbose) | |
| verbose=true | |
| ;; | |
| esac | |
| done | |
| if [[ "$verbose" == true ]]; then | |
| set -x | |
| fi | |
| # Delete branches marked as old/* | |
| git branch -l old/* | xargs git branch -D | |
| # Delete branches which have been merged into the default branch | |
| original_branch=$(git rev-parse --abbrev-ref HEAD) | |
| default_branch=$(git default-branch) | |
| git switch -q $default_branch | |
| git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do | |
| merge_base=$(git merge-base $default_branch $branch) | |
| [[ $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) == "-"* ]] && | |
| git branch -D $branch; | |
| done | |
| git switch -q $original_branch | |
| #!/bin/sh | |
| set -euxo pipefail | |
| git reset HEAD^ | |
| git add . | |
| git commit --amend --no-edit |
| #!/bin/sh | |
| git rev-parse --abbrev-ref HEAD |
| #!/bin/sh | |
| set -euo pipefail | |
| git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 |
| #!/bin/sh | |
| set -euo pipefail | |
| git default-branch | xargs git merge-base HEAD | xargs git diff |
| #!/bin/sh | |
| set -euo pipefail | |
| git diff --name-only --diff-filter=U --relative | \ | |
| sed "s/^/'/;s/$/'/" | \ | |
| xargs -n 10 -o vim -p | |
| #!/bin/sh | |
| set -euo pipefail | |
| if [[ $# -gt 0 ]]; then | |
| while : | |
| do | |
| case "$1" in | |
| -h | --help) | |
| echo "usage: git grep-branch [<pattern>]" | |
| exit 0 | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| done | |
| fi | |
| git branch -l *$1* | HEAD -n 1 | rev | cut -w -f 1 | rev |
| #!/bin/sh | |
| set -euo pipefail | |
| if [[ $# -gt 0 ]]; then | |
| case "$1" in | |
| -h | --help) | |
| echo "usage: git grep-worktree <pattern>" | |
| exit 0 | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| else | |
| exit 1 | |
| fi | |
| worktree_name=$(git worktree list | grep $1 | cut -w -f 1) | |
| echo $worktree_name | |
| #!/bin/sh | |
| git show --name-only --pretty=format: |
| #!/bin/sh | |
| set -euo pipefail | |
| base_branch=$(git default-branch | xargs git merge-base HEAD) | |
| git show --name-only --pretty=format: ${base_branch}..HEAD |
| #!/bin/sh | |
| set -eu | |
| verbose=false | |
| pattern= | |
| for arg in "$@"; do | |
| case "$arg" in | |
| -h | --help) | |
| echo "usage: git mark-resolved [--verbose] [<pattern>]" | |
| exit 0 | |
| ;; | |
| -v | --verbose) | |
| verbose=true | |
| ;; | |
| *) | |
| pattern=$arg | |
| ;; | |
| esac | |
| done | |
| if [[ "$verbose" == true ]]; then | |
| set -x | |
| fi | |
| files_to_resolve=$(git diff --name-only --diff-filter=U --relative) | |
| if [[ ! -z $pattern ]]; then | |
| files_to_resolve=$(echo $files_to_resolve | grep -E "$pattern") | |
| fi | |
| git add $files_to_resolve |
| #!/bin/sh | |
| set -eu | |
| print_help() { | |
| echo "usage: git merge-squash [--verbose] <branch>" | |
| } | |
| verbose=false | |
| branch= | |
| for arg in "$@"; do | |
| case "$arg" in | |
| -h | --help) | |
| exit 0 | |
| ;; | |
| -v | --verbose) | |
| verbose=true | |
| ;; | |
| *) | |
| branch=$arg | |
| ;; | |
| esac | |
| done | |
| if [[ -z "$branch" ]]; then | |
| print_help | |
| exit 2 | |
| fi | |
| if [[ "$verbose" == true ]]; then | |
| set -x | |
| fi | |
| git sd | |
| git s -c temp | |
| git merge --squash "$branch" | |
| git commit | |
| git switch "$branch" | |
| git default-branch | xargs git reset --hard | |
| git cp temp | |
| git branch -D temp |
| #!/bin/sh | |
| set -euo pipefail | |
| username=$(git config --get user.name) | |
| git for-each-ref --sort=committerdate --format='%(committerdate) %09 %(authorname) %09 %(refname)' | grep "$username" |
| #!/bin/sh | |
| set -euo pipefail | |
| if [[ $# -gt 0 ]]; then | |
| while : | |
| do | |
| case "$1" in | |
| -h | --help) | |
| echo "usage: git new <message>" | |
| exit 0 | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| done | |
| fi | |
| set -x | |
| git add --all | |
| git commit -m "$1" |
| #!/bin/sh | |
| set -euo pipefail | |
| branch=$(git rev-parse --abbrev-ref HEAD) | |
| for arg in "$@"; do | |
| case "$arg" in | |
| -h | --help) | |
| echo "usage: git punt [<branch>]" | |
| exit 0 | |
| ;; | |
| *) | |
| branch=$arg | |
| ;; | |
| esac | |
| done | |
| newbranch="punt/$branch" | |
| set -x | |
| git branch -m $branch $newbranch |
| #!/bin/sh | |
| set -eu | |
| for arg in "$@"; do | |
| case "$arg" in | |
| -h | --help) | |
| echo "usage: git rename" | |
| exit 0 | |
| ;; | |
| esac | |
| done | |
| git commit --amend | |
| #!/bin/sh | |
| set -euxo pipefail | |
| git reset --hard origin/$(git current-branch) |
| #!/bin/sh | |
| set -euxo pipefail | |
| branch=$(git default-branch) | |
| git fetch upstream | |
| git switch $branch | |
| git merge upstream/$branch |
| #!/bin/sh | |
| set -euo pipefail | |
| branch=$(git rev-parse --abbrev-ref HEAD) | |
| for arg in "$@"; do | |
| case "$arg" in | |
| -h | --help) | |
| echo "usage: git unpunt [<branch>]" | |
| exit 0 | |
| ;; | |
| *) | |
| branch=$arg | |
| ;; | |
| esac | |
| done | |
| newbranch=$(echo $branch | cut -c6-) | |
| set -x | |
| git branch -m $branch $newbranch |
| #!/bin/sh | |
| mkdir -p ~/.git-commands | |
| cp ./git-* ~/.git-commands | |
| chmod +x ~/.git-commands/* |
MIT License
Copyright (c) 2022 Kevin Beaulieu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.