Last active
October 1, 2025 12:14
-
-
Save pvaviloff/375fcb018c970ef96f3e9a368dec666d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [alias] | |
| # checkout branches | |
| ch = "!git checkout \"$@\"; git status" | |
| pb = "!git pull; git checkout -b \"$@\" origin/\"$@\"; git status" | |
| # short codes | |
| pp = "!git pull; git push" | |
| mb = "!git pull; git merge \"$@\"" | |
| br = "!git status; git branch" | |
| st = "!git status" | |
| rb = "!f() { git rebase -i $(git merge-base \"$1\" HEAD); }; f" | |
| abort = "!git merge --abort" | |
| # create branch and checkout | |
| new = checkout -b | |
| # log showing changed files | |
| lg = log --pretty=format:"%C(yellow)%h\\ %C(red)%ad%Cred%d\\ %C(cyan)%s\\ %C(blue)[%cn]" --decorate --numstat --date=short | |
| # drop branch | |
| del = branch -D | |
| # The stacking workflow (https://www.stacking.dev/) | |
| # Amend the last commit on the current branch. | |
| # Example: git amend | |
| amend = "!f() { \ | |
| curr=$(git rev-parse --abbrev-ref HEAD); \ | |
| parent=$(awk -v c=$curr '$3==c {print $1}' .git/stack); \ | |
| if [ -z \"$parent\" ]; then \ | |
| echo "Error: cannot detect parent branch for $curr" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| if git diff --quiet && git diff --cached --quiet; then \ | |
| echo 'Error: no changes to commit' >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| if [ $(git rev-list --count $parent..HEAD) -eq 0 ]; then \ | |
| echo 'Error: no commits on this branch to amend' >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| git add . && git commit --amend --no-edit; \ | |
| }; f" | |
| # Rebase all child branches in the stack after resolving conflicts. | |
| # Example: git restack | |
| restack = "!f() { \ | |
| curr=$(git rev-parse --abbrev-ref HEAD); \ | |
| parent=$(awk -v c=$curr '$3==c {print $1}' .git/stack); \ | |
| if [ -z \"$parent\" ]; then \ | |
| echo \"Error: cannot detect parent branch for $curr\" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| parent=$curr; \ | |
| while true; do \ | |
| child=$(awk -v p=$parent '$1==p {print $3}' .git/stack); \ | |
| [ -z \"$child\" ] && break; \ | |
| echo \"Finding branch-point commit of $child in $parent reflog...\"; \ | |
| base=\"\"; \ | |
| for entry in $(git reflog refs/heads/$parent --pretty=%H); do \ | |
| if git merge-base --is-ancestor $entry $child; then \ | |
| base=$entry; \ | |
| break; \ | |
| fi; \ | |
| done; \ | |
| if [ -z \"$base\" ]; then \ | |
| echo \"Error: cannot find base commit for $child\" >&2; \ | |
| break; \ | |
| fi; \ | |
| echo \"Rebasing $child onto $parent\"; \ | |
| git rebase --onto $parent $base $child || break; \ | |
| parent=$child; \ | |
| done; \ | |
| git checkout $curr; \ | |
| }; f" | |
| # Create a new branch, commit changes, and link it in the stack. | |
| # Example: git create feature-branch "Add new feature" | |
| create = "!f() { \ | |
| branch=$1; \ | |
| msg=$2; \ | |
| if [ -z \"$branch\" ]; then \ | |
| echo 'Error: branch name not provided' >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| if [ -z \"$msg\" ]; then \ | |
| echo 'Error: commit message not provided' >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| if git rev-parse --verify --quiet \"refs/heads/$branch\" >/dev/null; then \ | |
| echo \"Error: branch $branch already exists\" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| if git diff --quiet && git diff --cached --quiet; then \ | |
| echo 'Error: no changes to commit' >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| base=$(git rev-parse --abbrev-ref HEAD); \ | |
| git checkout -b $branch; \ | |
| echo \"$base -> $branch\" >> .git/stack; \ | |
| echo \"Saved stack link: $base -> $branch\"; \ | |
| git add .; \ | |
| git commit -m \"$msg\"; \ | |
| }; f" | |
| # Amend the current branch and rebase all child branches. | |
| # Example: git modify | |
| modify = "!git amend; git restack" | |
| # Push current branch and all child branches to origin. | |
| # Example: git submit | |
| submit = "!f() { \ | |
| curr=$(git rev-parse --abbrev-ref HEAD); \ | |
| parent=$(awk -v c=$curr '$3==c {print $1}' .git/stack); \ | |
| if [ -z \"$parent\" ]; then \ | |
| echo "Error: cannot detect parent branch for $curr" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| parent=$curr; \ | |
| while true; do \ | |
| echo \"Pushing $parent\"; \ | |
| git push --force origin $parent; \ | |
| child=$(awk -v p=$parent '$1==p {print $3}' .git/stack); \ | |
| [ -z \"$child\" ] && break; \ | |
| parent=$child; \ | |
| done; \ | |
| }; f" | |
| # Sync current branch with its parent, then restack children. | |
| # Example: git sync | |
| sync = "!f() { \ | |
| curr=$(git rev-parse --abbrev-ref HEAD); \ | |
| parent=$(awk -v c=$curr '$3==c {print $1}' .git/stack); \ | |
| if [ -z \"$parent\" ]; then \ | |
| echo \"Error: cannot detect parent branch for $curr\" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| echo \"Fetching parent $parent\"; \ | |
| git fetch origin $parent:$parent || exit 1; \ | |
| echo \"Finding base commit for $curr relative to $parent\"; \ | |
| base=\"\"; \ | |
| for entry in $(git reflog refs/heads/$parent --pretty=%H); do \ | |
| if git merge-base --is-ancestor $entry $curr; then \ | |
| base=$entry; \ | |
| break; \ | |
| fi; \ | |
| done; \ | |
| if [ -z \"$base\" ]; then \ | |
| echo \"Error: cannot find base commit for $curr\" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| echo \"Rebasing $curr onto $parent\"; \ | |
| git rebase --onto $parent $base $curr || exit 1; \ | |
| echo \"Restacking children of $curr\"; \ | |
| git restack; \ | |
| }; f" | |
| # Delete a branch from the stack, rewire children, and restack. | |
| # Example: git delete feature-branch | |
| delete = "!f() { \ | |
| target=$1; \ | |
| if [ -z \"$target\" ]; then \ | |
| echo 'Error: branch name required' >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| if ! git show-ref --verify --quiet refs/heads/$target; then \ | |
| echo \"Error: branch $target does not exist\" >&2; \ | |
| exit 1; \ | |
| fi; \ | |
| parent=$(awk -v c=$target '$3==c {print $1}' .git/stack); \ | |
| child=$(awk -v p=$target '$1==p {print $3}' .git/stack); \ | |
| echo \"Deleting branch $target\"; \ | |
| git branch -D $target || exit 1; \ | |
| if [ -f .git/stack ]; then \ | |
| tmp=$(mktemp); \ | |
| awk -v t=$target '$1!=t && $3!=t {print}' .git/stack > $tmp; \ | |
| if [ -n \"$child\" ] && [ -n \"$parent\" ]; then \ | |
| echo \"$parent -> $child\" >> $tmp; \ | |
| echo \"Rewired: $parent -> $child\"; \ | |
| fi; \ | |
| mv $tmp .git/stack; \ | |
| fi; \ | |
| if [ -n \"$child\" ] && [ -n \"$parent\" ]; then \ | |
| echo \"Rebasing $child onto $parent\"; \ | |
| base=\"\"; \ | |
| for entry in $(git reflog refs/heads/$parent --pretty=%H); do \ | |
| if git merge-base --is-ancestor $entry $child; then \ | |
| base=$entry; \ | |
| break; \ | |
| fi; \ | |
| done; \ | |
| if [ -n \"$base\" ]; then \ | |
| git rebase --onto $parent $base $child || exit 1; \ | |
| git checkout $child; \ | |
| git restack; \ | |
| fi; \ | |
| fi; \ | |
| }; f" | |
| [core] | |
| # Don't paginate output by default | |
| pager = cat | |
| [color] | |
| ui = true | |
| [color "branch"] | |
| current = cyan bold reverse | |
| local = cyan bold | |
| remote = red | |
| [color "diff"] | |
| meta = yellow bold | |
| frag = magenta bold | |
| old = red bold | |
| new = green bold | |
| [color "status"] | |
| header=cyan bold | |
| added = green bold | |
| changed = magenta bold | |
| untracked = red bold |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment