Make Yourself Some Git Plugins
You may already be aware of some popular git plugins:
- git-recursive-blame
- git-fire
- git-blame-someone-else
- git-secret
- git-standup
- git-recent
- git-fresh
- git-autosave (wait, who made that?)
Many of you likely already know how to implement such a plugin, but I want to provide a short tutorial for everyone else.
A command that I often find useful is git publish. If the branch
doesn't already exist on the remote, it's nice to be able to have an alias for
git push --set-upstream origin $BRANCH_NAME. Some plugins do this
automatically, but it's very easy to write, so there's not much reason we
can't implement it ourselves.
#!/usr/bin/env sh
BRANCH=${git rev-parse --abbrev-ref HEAD}
git push --set-upstream origin $BRANCH
Now that we have that, we can make it accessible to Git. The easiest way to do
this is to put the script in your ~/.local/bin directory, since
it's usually already in the PATH. We'll call the full file:
~/.local/bin/git-publish. We won't add a .sh file
extension, because the shebang already tells the OS how to run this program.
Then we just need to make the program executable. Run
chmod +x ~/.local/bin/git-publish, and you're done. We can now
run it as git publish. When Git sees the publish
command, it will look through the path to see if an executable called
git-publish exists, and run that.
See how easy that was? If you want to do something more complicated with Git, I recommend reading the Git Internals chapter from Pro Git. Git is really more of a database than a version control system, and I'm always disappointed by the lack of creativity people put into git plugins. Writing a sillier project would be too long for this blog post, but it'd be cool to see someone make an MMO using Git as the database. The sky is the limit.