From b7e2019eeed38d3b22f07c51aac8578fd53c9bee Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 13 Dec 2023 21:39:47 -0500 Subject: Move aliases to scripts. The git aliases mechanism is pretty limited; there's some stuff you can't really do without dropping to a shell. If you're going to do that, then custom subcommand scripts are more flexable than aliases that start with ! are. --- .DS_Store | Bin 0 -> 6148 bytes README.md | 41 ---------------------------- aliases.gitconfig | 78 ------------------------------------------------------ bin/.DS_Store | Bin 0 -> 6148 bytes bin/git-amend | 4 +++ bin/git-bdiff | 11 ++++++++ bin/git-blog | 11 ++++++++ bin/git-fall | 5 ++++ bin/git-fixup | 13 +++++++++ bin/git-lol | 4 +++ bin/git-publish | 10 ------- bin/git-rewrite | 8 ++++++ bin/git-squash | 14 ++++++++++ bin/git-start | 13 --------- bin/git-this | 5 ++++ 15 files changed, 75 insertions(+), 142 deletions(-) create mode 100644 .DS_Store delete mode 100644 README.md delete mode 100644 aliases.gitconfig create mode 100644 bin/.DS_Store create mode 100755 bin/git-amend create mode 100755 bin/git-bdiff create mode 100755 bin/git-blog create mode 100755 bin/git-fall create mode 100755 bin/git-fixup create mode 100755 bin/git-lol delete mode 100755 bin/git-publish create mode 100755 bin/git-rewrite create mode 100755 bin/git-squash delete mode 100755 bin/git-start create mode 100755 bin/git-this diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md deleted file mode 100644 index c01e4e6..0000000 --- a/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Premises: - -* Every project has at least one "canonical" repository. The canonical repo - tracks the project's official history. New clones are created by cloning - the canonical repo; the aliases below assume that the `origin` remote - points to the canonical repo. - -* Most development happens on short-lived feature branches, which are merged - into the canonical repo's `master` branch when accepted. This merge should - be non-fastforward, but the alias suite doesn't care. - -* Developers publish _proposed_ changes to their own repositories, not to - the canonical repository directly. The aliases below expect the user's - personal repo to be associated with a remote named with the user's login - name. (It's fine if this is an alias for `origin`, provided you're - extremely careful with the `publish` alias.) - -* Branches in a developer's personal repository are "unstable" and may be - rewritten by the author. (It's up to you to communicate with your team; - if you're working with someone on a shared feature branch, using - `publish` will lead to obnoxious cleanup work.) - -* You have `push.default` set to `simple`. (If your version of `git` doesn't - support this option, upgrade. The default behaviour of `git push` is - unsupportably bad.) - -* You sometimes want to use normal Git commands, too. (Otherwise, why aren't - you using `git-flow`, `tig`, or some other workflow frontend?) - -# Usage: - -Read the inline comments in [aliases.gitconfig](aliases.gitconfig). - -# Installation: - - $ git config --global --add include.path '/path/to/aliases.gitconfig' - -## Removal: - - $ git config --global --unset include.aliases \ - '/path/to/aliases.gitconfig' diff --git a/aliases.gitconfig b/aliases.gitconfig deleted file mode 100644 index f619ae5..0000000 --- a/aliases.gitconfig +++ /dev/null @@ -1,78 +0,0 @@ -[alias] - ## Alias management - # List aliases: `git aliases` - aliases = config --global --get-regexp alias[.] - - ## Remote management - # Bring all remotes up to date: `git fall` (this is morally - # equivalent to `git remote update --prune`, but easier to type). - fall = fetch --all --prune - # Bring this branch up to date with its upstream, safely: `git up` - # This will fail (intentionally) if the current branch has diverged - # from upstream; use `git reset`, `git rebase`, or `git merge` to - # re-converge the branch as appropriate. I generally only use this to - # bring local `master` up to date with `origin/master` immediately - # before using `git accept`. - up = pull --ff --ff-only - # Fast-forward the current branch: `git ff [BRANCHNAME]`. Morally - # equivalent to `git up` if you fetch things by hand and have - # `merge.defaultToUpstream` set to `true` (which you should).) - ff = merge --ff --ff-only - # Configure `origin` to fetch Github pull requests: `git prhub` - this - # will cause `git fetch` to create local refs named `refs/pull/N` for - # each pull request's source branch. - prhub = config --add remote.origin.fetch +refs/pull/*/head:refs/pull/* - # Configure `origin` to fetch Stash pull requests: `git prstash` - # Atlassian is very insistent that these refs are for internal use - # only and are unsupported; they've changed how they work at least - # once in recent history. If this breaks, you get to keep both pieces. - prstash = config --add remote.origin.fetch +refs/pull-requests/*/from:refs/pull/* - - ## Branch lifecycle - # Branch log for the current branch: `git blog [log options]` - blog = log HEAD@{upstream}..HEAD - # Branch one-line summary (equivalent to `git blog --oneline`) - bsummary = log --oneline HEAD@{upstream}..HEAD - # Aggregate diff of the current branch: `git bdiff [diff options]` - bdiff = diff HEAD@{upstream}...HEAD - # "Accept" a branch by merging it: `git accept BRANCHNAME` - this - # always creates a merge commit if it succeeds, making it easier to - # pick out branch merges in history. (See `git up`, above, for more - # usage advice.) - accept = merge --no-ff - # Rewrite the current branch, in place: `git rewrite` - unlike `git - # rebase`, this does _not_ advance the branch onto new upstream - # changes. You can use this to clean up branch history without - # worrying about conflicts with others' changes at the same time. - rewrite = rebase --interactive --onto HEAD...@{upstream} - # Create a branch detached from history: `git sever BRANCHNAME` - this - # is a bit of a niche command; I create expurgated branches from - # private projects more often than some people. - sever = checkout --detach - # Delete all branches merged into origin/maser: `git prune-merged` - prune-merged = "!f() { git for-each-ref refs/heads/* --merged | while read hash type ref; do branch=\"$(git rev-parse --abbrev-ref \"${ref}\")\"; git branch -d \"${branch}\"; done; }; f" - - ## Commit authoring - ## The following aliases interact with `git rebase --autosquash`; I - ## recommend setting `rebase.autosquash` to `true` to make this the - ## default behaviour. See `man git-rebase` for a thorough explanation. - # Stage the work tree, verbatim, including removals and renames: `git - # this` - try to keep `git status` clean all the time, or this will - # make you so, so sad. `.git/info/exclude` is a great help for this. - this = add --all :/ - # Stage this subdirectory of the work tree, verbatim, including - # removals and renames: `git these`. - these = add --all . - # Replace the most recent commit: `git amend [commit options]`. - amend = commit --amend --no-edit - # Retrofit changes onto an old commit during the next rebase/rewrite: - # `git fixup COMMITISH` (for example, `git fixup HEAD`). - fixup = commit --fixup - # Retrofit changes onto an old commit during the next rebase/rewrite, - # adding an additional comment `git squash COMMITISH` (for example, - # `git squash HEAD`). - squash = commit --squash - - ## Working with history - # Simple text-based commit graph: `git lol [BRANCHES|--all]` - lol = log --graph --oneline --decorate diff --git a/bin/.DS_Store b/bin/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/bin/.DS_Store differ diff --git a/bin/git-amend b/bin/git-amend new file mode 100755 index 0000000..04430a6 --- /dev/null +++ b/bin/git-amend @@ -0,0 +1,4 @@ +#!/bin/bash -e + +# Replace the most recent commit: `git amend [commit options]`. +exec git commit --amend --no-edit "$@" diff --git a/bin/git-bdiff b/bin/git-bdiff new file mode 100755 index 0000000..eb93d13 --- /dev/null +++ b/bin/git-bdiff @@ -0,0 +1,11 @@ +#!/bin/bash -e + +# Diff for a branch, starting from where it diverges from its upstream. + +BRANCH=HEAD +if [ $# -gt 0 ]; then + BRANCH="$1" + shift +fi + +exec git diff "${BRANCH}@{upstream}" "${BRANCH}" "$@" diff --git a/bin/git-blog b/bin/git-blog new file mode 100755 index 0000000..8be71e7 --- /dev/null +++ b/bin/git-blog @@ -0,0 +1,11 @@ +#!/bin/bash -e + +# Log for a branch, starting from where it diverges from its upstream. + +BRANCH=HEAD +if [ $# -gt 0 ]; then + BRANCH="$1" + shift +fi + +exec git log "${BRANCH}@{upstream}...${BRANCH}" "$@" diff --git a/bin/git-fall b/bin/git-fall new file mode 100755 index 0000000..03b31de --- /dev/null +++ b/bin/git-fall @@ -0,0 +1,5 @@ +#!/bin/bash -e + +# Alias for `git remote update`. + +exec git remote update "$@" diff --git a/bin/git-fixup b/bin/git-fixup new file mode 100755 index 0000000..8910b2a --- /dev/null +++ b/bin/git-fixup @@ -0,0 +1,13 @@ +#!/bin/bash -e + +# Retrofit changes onto an old commit during the next rebase/rewrite: +# `git fixup [COMMITISH]` (for example, `git fixup HEAD`). + +COMMIT=HEAD +if [ $# -gt 0 ]; then + COMMIT="$1" + shift +fi + + +exec git commit --fixup "${COMMIT}" "$@" diff --git a/bin/git-lol b/bin/git-lol new file mode 100755 index 0000000..1476889 --- /dev/null +++ b/bin/git-lol @@ -0,0 +1,4 @@ +#!/bin/bash -e + +# Simple text-based commit graph: `git lol [BRANCHES|--all]` +exec git log --graph --oneline --decorate "$@" diff --git a/bin/git-publish b/bin/git-publish deleted file mode 100755 index 0016764..0000000 --- a/bin/git-publish +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -e - -# Copy your current branch to a "publishing" remote. -# -# By default, this remote is origin. However, you can set `publish.remote` to -# publish to another repository (eg. my-fork). - -REMOTE="$(git config publish.remote || echo "origin")" - -exec git push --force-with-lease "$@" "${REMOTE}" HEAD diff --git a/bin/git-rewrite b/bin/git-rewrite new file mode 100755 index 0000000..52bcaf9 --- /dev/null +++ b/bin/git-rewrite @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# Rewrite the current branch, in place: `git rewrite` - unlike `git +# rebase`, this does _not_ advance the branch onto new upstream +# changes. You can use this to clean up branch history without +# worrying about conflicts with others' changes at the same time. + +exec git rebase --interactive --onto HEAD...@{upstream} diff --git a/bin/git-squash b/bin/git-squash new file mode 100755 index 0000000..26c363c --- /dev/null +++ b/bin/git-squash @@ -0,0 +1,14 @@ +#!/bin/bash -e + +# Retrofit changes onto an old commit during the next rebase/rewrite, +# adding an additional comment `git squash COMMITISH` (for example, +# `git squash HEAD`). + +COMMIT=HEAD +if [ $# -gt 0 ]; then + COMMIT="$1" + shift +fi + + +exec git commit --squash "${COMMIT}" "$@" diff --git a/bin/git-start b/bin/git-start deleted file mode 100755 index 8251fa4..0000000 --- a/bin/git-start +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -e - -# Create a branch: `git start BRANCHNAME` (protip: run `git fall` first.) The -# new branch will track origin/main by default, or origin/master if origin/main -# doesn't exist. Tracking info gets used below. - -if git rev-parse --quiet --verify origin/main > /dev/null; then - exec git checkout --track origin/main -b "$@" -elif git rev-parse --quiet --verify origin/master > /dev/null; then - exec git checkout --track origin/master -b "$@" -fi - -exec git checkout --track origin/main -b "$@" diff --git a/bin/git-this b/bin/git-this new file mode 100755 index 0000000..913a37d --- /dev/null +++ b/bin/git-this @@ -0,0 +1,5 @@ +#!/bin/bash -e + +# Stage the work tree verbatim + +exec git add --all :/ -- cgit v1.2.3