Git is so awesome and packs so much power that I could hardly fit it all in a blog post (or 100 for that matter). What this post will talk about though, are a couple of ways to extend your git for it to better serve you on your everyday tasks.
This is post is not about ZSH, but it is awesome and you should install it. All the configs will assume you are using it, but surely there are ways of doing the same for your shell of choice.
hub is a command line tool that wraps
gitin order to extend it with extra features and commands that make working with GitHub easier.
This is the description taken straight out of the project’s README. Hub is written by the guys at Github, so it is very much compliant with everything on the site. As of recently you can install it with Homebrew (non-mac users will have to compile it manuallly, I believe).
Now you can use
hub and all it’s powers. The sane thing to do though, is to
hub, which works perfectly as
hub will delegate all non-hub
Just open your
.zshrc and add the alias:
When you brew install
hub you will see that it installs completion files to
If you run
echo $fpath on your terminal that path should be there.
stands for functions path and you can store you functions in any directory
fpath. Read more about zsh functions
This will provide auto-complete functionality for all your
If you are like me, though, and
git is the command you use more often (about
30% of the time in my case), you will probably want to alias it to something
shorter, such as
g maps to
git which maps to
hub. Great! We have, however,
introduced an issue. Auto-complete is broken. That is because the git auto
completion function is only expecting
gitk as commands to auto
You can add
g to that set easily enough. Again, open your
.zshrc and add
You should have everything ready to go.
Hub adds some really nice things, but what about those specific commands you
love to use? At some point all of us have added commands as aliases in
This is not inherently bad, but it can go out of hand pretty quickly. Moreover, you don’t really have a lot of scripting power with these aliases. As you might have guessed by now, there is a better way of doing this and it is so cool that even some of the builtin commands use this strategy.
The basic idea is that any executable script on you
PATH that is named
git-some-name will be available as a git subcommand, which means you could do
git some-name to run the script.
Git is so awesome that it even adds them to
git help -a under the title “git
commands available from elsewhere on your $PATH”, which will then power the auto
completion, so that will also work for any command you add.
Going back to our example, there’s a couple of things to do to remove it from an
alias into a command, add a directory to the
PATH and create a script on that
1 2 3
You should now be able to remove the alias from the
gitconfig and still be able
Git will just grab the scripts that follow the aforementioned convention and run them. That means that as long as the shebang is correctly set, you can write a script in any scripting language.
Here’s one in ruby:
1 2 3
Just name it
git-hello, put it in your
git_commands directory and you should
be able to type
g hello and have git say “Hello” back.