From 613f1f8e3712539654c9e910adc48ba3cf1d5d13 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 19 Feb 2024 18:04:45 -0600 Subject: [PATCH] Add Extend Git With Custom Commands as a git TIL --- README.md | 3 ++- git/extend-git-with-custom-commands.md | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 git/extend-git-with-custom-commands.md diff --git a/README.md b/README.md index 0365545..087973d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1370 TILs and counting..._ +_1371 TILs and counting..._ --- @@ -271,6 +271,7 @@ _1370 TILs and counting..._ - [Dry Runs in Git](git/dry-runs-in-git.md) - [Exclude A File From A Diff Output](git/exclude-a-file-from-a-diff-output.md) - [Excluding Files Locally](git/excluding-files-locally.md) +- [Extend Git With Custom Commands](git/extend-git-with-custom-commands.md) - [Find And Remove Files That Match A Name](git/find-and-remove-files-that-match-a-name.md) - [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md) - [Find The Initial Commit](git/find-the-initial-commit.md) diff --git a/git/extend-git-with-custom-commands.md b/git/extend-git-with-custom-commands.md new file mode 100644 index 0000000..b65d2ca --- /dev/null +++ b/git/extend-git-with-custom-commands.md @@ -0,0 +1,26 @@ +# Extend Git With Custom Commands + +I recently learned about the [`git +absorb`](https://github.com/tummychow/git-absorb) command. It is interesting in +its own right, but I bring it up because it isn't a command that is built in to +git. When I was looking at the installation instructions for it, it didn't say +anything about how to _register_ the command with `git`. + +How is git supposed to know about it? How do you extend git with custom +commands? + +What I learned exploring those questions is that `git` will execute any command +on your _path_ with a `git-` naming convention. + +So, if I create a executable binary called `git-taco`, add it to my path, and +then run `git taco` (notice, no dash when I run it), `git` will run my custom +binary. + +In the same way, if you download `git-absorb` and add it to your path, `git` +will run it for you when you enter `git absorb ...`. + +You can even type something like `where git-` and then hit tab to prompt your +shell to display a list of a varity of other `git` commands, most of which +probably ship with `git`. + +[source](https://twitter.com/jbrancha/status/1756361704160530555)