Skip to content

Instantly share code, notes, and snippets.

@sirosen
Last active December 31, 2015 06:49
Show Gist options
  • Save sirosen/7950217 to your computer and use it in GitHub Desktop.
Save sirosen/7950217 to your computer and use it in GitHub Desktop.
Simple git alias demo.

Example ~/.gitconfig is given below. In it, I define a simple alias that will print a nice log graph, "logtree". "logtree" is invoked from the commandline as "git logtree". Arguments are passed, so I can do "git logtree --oneline" and get the expected result.

[user]
    name = "Stephen Rosen"
    email = "sirosen@uchicago.edu"
[alias]
    logtree = "log --graph --decorate --all"
[push]
    default = simple

Note that you can invoke non-git commands in an alias, although the syntax is somewhat odd.

[user]
    name = "Stephen Rosen"
    email = "sirosen@uchicago.edu"
[alias]
    logtree = "log --graph --decorate --all"
    hello = "!bash echo 'hello'"
[push]
    default = simple

Invoking multiple commands is difficult, and does not always behave consistently across platforms. I more strongly recommend using bash scripts invoked with "!bash path/to/myscript.sh"

So consider a script, pushall.sh

#!/bin/bash

git push origin
git push upstream
git push devserver

put it in ~/.gitscripts/ or a similarly named directory. You can then add an alias

[alias]
    pushall = "!bash ~/.gitscripts/pushall.sh"

and invoke it with git pushall in any git repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment