/ contents / adding commands to git

adding commands to git

did you know that you can add commands to git by naming them right and placing them in your path?

if you put this:

git branch | awk '/\*/ {print $2}'

into a file called git-current-branch, make it executable and put it somewhere in $PATH (i use ~/bin which i've added to $PATH), you will be able to use it like this:

$ git current-branch

and bash/zsh completions will tab complete them too

that example would probably make more sense to be an alias, but what about something like this:


if [ -z "$branch" ]; then
branch=$(git current-branch)

git branch -u origin/${branch}

ooh, or



if [ -z "$function" ] || [ -z "$file" ]; then
echo 'usage: git log-function <function> <file>'
exit 1

git log -L ":$function:$file"

i'm sure you can come up with something more useful