5 ms·
wait wait wait... are you saying that having an executable at ~/bin/git-co-commit will automatically create `git co-commit`? Wouldn't it merely create a 'git-co
by pluc 4y ago
wait wait wait... are you saying that having an executable at ~/bin/git-co-commit will automatically create `git co-commit`? Wouldn't it merely create a 'git-co-commit' command you can access as that user as long as it's in your $PATH? What is integrating it in the `git` program?? Or was it just a typo in your example and you actually type `git-co-commit` and not `git co-commit`?
- jmillikin 4y agoGit will automatically prefix a subcommand with `git-` and try to execute a command with that name. https://blog.sebastian-daschner.com/entries/custom-git-subcommands https://blog.sebastian-daschner.com/entries/custom-git-subco... Many "built-in" Git commands are themselves separate executables. My Linux machine has them in `/usr/lib/git-core/`, and my macOS machine has them in `/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/`.
- mrmattyboy 4y agoI had the same reaction!... but just tested it and lo and behold it works! [user@user ~]# cat > ~/bin/git-test-me <<'EOF' #!/bin/bash echo hi EOF [user@user ~]# chmod +x ~/bin/git-test-me [user@user ~]# git test-me hi
- alexdowad 4y agoTry 'strace git blah', it will be educational.
- mijoharas 4y agoyep! all git subcommands are separate binaries. Check out `ls /usr/lib/git-core` (that's the path on my machine). Or you can `locate git-add` or something to check where they're located on your machine. I have a tiny fzf script called `git select` to give me a nice interface for selecting branches I've recently worked on. Just call the script `git-select` and stick it somewhere in your path. In the spirit of this question, my one is here: !/bin/zsh alias git_my_branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'" local selected_branch=$(git_my_branches --color | fzf --ansi --tac | awk '{print $1}') if [ "$selected_branch" != '*' ]; then git checkout $selected_branch fi
- junon 4y agoCorrect. Git will try to run a built in subcommand, and if it doesn't exist, it'll fall back to trying to run `git-some-command`. Many Linux tools do this. Rust's cargo is another. In fact, `man` itself can take multiple positional arguments and will concatenate them with a hyphen to perform the lookup.
- cturtle 4y agoAs others mentioned, yes! If you’re curious on how it works I write a sort of deep-dive on the git internals of how this works: https://nathancraddock.com/blog/2022/custom-git-commands/ https://nathancraddock.com/blog/2022/custom-git-commands/