
Working with git? These aliases will save you hours - pkrumins
http://www.catonmat.net/blog/git-aliases
======
yuvadam
Personally, I find these aliases a bit _too_ terse.

Aliases are important for enhanced productivity, but _shell_ aliases are too
much. I find these _git_ aliases much more comfortable:

    
    
        alias.st=status
        alias.co=checkout
        alias.com=checkout master
        alias.cam=commit -a -m
        alias.cm=commit -m
        alias.br=branch
    

push, pull, merge, rebase and the rest are infrequently used, so I don't alias
them at all. Using shell aliases (as opposed to git aliases) is unjustified
IMO, as is the horrible

    
    
        alias g='git'
    

which gives me the creeps.

~~~
pdelgallego
just another one

alias grm="git status | grep deleted | awk '{print \$3}' | xargs git rm"

~~~
bronson
I have a similar thing in my .gitconfig:

    
    
        [alias]
          rm-a  = "!git ls-files -z --deleted | xargs -0 git rm"

------
Swizec
I'm a bit skeptical on the usefulness of this. As far as my coder nose goes,
this has a really really bad smell and if I saw this sort of stuff in my
codebase I would feel an urge to punch somebody.

From a productivity point of view, since this is presumably used by
developers, we can safely assume these are people who spend at least 10 hours
a day typing (coding, internet etc.). Most of our lives are spend behind a
keyboard yes?

That being the case, we can safely assume that most of us are pretty good
typists. Even a marginally good typist can punch the keyboard at 60 words per
minute. Considering the average English word length of 5.7 characters that
gives us a speed of 342 characters per minute, or 5.7 per second.

Do you really _really_ need to increase your mental load for translating
acronyms/abbreviations into words in order to save fractions of a second?
Really?

~~~
mechanical_fish
_if I saw this sort of stuff in my codebase..._

Your codebase should be optimized for reading. Your aliases file should be
optimized for very, very frequent typing.

These are different goals, so naturally the solutions look different.

~~~
5teev
Typing on the command line is not like typing in a code file: it's perhaps the
least forgiving environment for typos, and tiny mistakes can have huge
consequences. A good typist can re-type the correct text after the command
finishes--maybe a moment too late. A good coder takes pains to avoid the
mistake in the first place.

~~~
mechanical_fish
_tiny mistakes can have huge consequences_

Yes, that's why we are not discussing the creation of easily typed aliases for
"rm -rf". That would be bad.

Instead we are discussing aliases for a bunch of fairly innocent Git commands,
most of which are reversible in case of catastrophic accident.

I admit that I do have a four-character abbreviation for "git reset --hard".
Maybe that will burn me one day, though I rarely pile up so many uncommitted
changes that I have much at risk. Or maybe I'll make that shortcut a little
longer.

~~~
nevinera
It won't burn you, the commits are still around until you get garbage
collected.

------
unwind
I think more can be saved by learning to use the shell (e.g. bash) better.

For instance, since the shell has command history that _persists_ between
sessions, once you've run e.g. "git push" once, you can run it again by typing
e.g. "^R pu" (including the space to make it more unique). That's more
keypresses than just "gp", but way clearer and more portable since it will
work wherever you have Bash, not just where your particular aliases are
installed.

~~~
tednaleid
I use shell history all the time, but I don't personally find it useful to use
for really common operations. I agree with the OP that commands that you
execute 10's or 100's of times a day should be made as short as possible and
they'll be part of muscle memory.

You can't rely on muscle memory for history commands as you always need to
pause and verify that history found what you were expecting it to find. If
your history looked like this (real shell history for me):

    
    
        git push
        ssh ec2-75-101-198-99.compute-1.amazonaws.com
    

the ^R would find the ssh command first, so you can't trust that "^Rpu" will
always find the command so muscle memory can't set in and will slow you down

~~~
bcl
I _love_ ^R

But make sure you've found the command you really thought you were looking for
before mashing the return key. Sometimes my muscle memory is a bit too fast...

~~~
pkrumins
If you love ^R, you'll also love [http://www.catonmat.net/blog/the-definitive-
guide-to-bash-co...](http://www.catonmat.net/blog/the-definitive-guide-to-
bash-command-line-history/)

------
nuclear_eclipse
If you really want to save time and keystrokes, use git-sh so that you don't
even need to type (or alias) git itself. You can still run all your normal
shell commands with it too.

<https://github.com/rtomayko/git-sh>

~~~
rtomayko
There's a list of short aliases enabled in git-sh by default here:

<http://rtomayko.github.com/git-sh/>

------
tonyskn
If you're using ZSH, Oh-my-zsh has a very nice git plugin
[https://github.com/robbyrussell/oh-my-
zsh/blob/master/plugin...](https://github.com/robbyrussell/oh-my-
zsh/blob/master/plugins/git/git.plugin.zsh)

------
erikabele
I'm totally fine with auto-completion, no need for aliases here though it
might make sense if you are using the same longish command over and over
again...

E.g. the following does the trick for tcsh, search the web for '<myfavshell>
git completion' and you'll find your way:

set gitcmds= ( `ls /usr/local/bin/git-*|sed ’s/\/usr\/local\/bin\/git-//g’` )
complete git “p/1/($gitcmds)/” ‘n/branch/`git branch|cut -c 3-`/’ ‘n/co/`git
branch|cut -c 3-`/’ ‘n/remote/(show add rm prune update)/’ ‘N/remote/`git
remote`/’

------
adriand
I love shell aliases and have recently taken to aliasing as much stuff as
possible. For example, I journal my thoughts on a more or less daily basis and
I store the file in a git-tracked repo, so I have this alias:

    
    
      alias think="cd ~/Documents/docrepo && git pull && mvim personal/thoughts.htm"
    

When I want to think I just enter "think".

I also set up aliases for my most commonly worked on projects that cd into the
correct folder, set the correct rvm version, etc.

------
trangatrang
I'm too scared to add -am to my commit alias but these are pretty reasonable
in my opinion... Can't live without them, and have definitely convinced some
others that this is the way to go. On another note, I can't wait until there
is an actual GUI that makes these aliases obsolete by saving us even more
time.

git st (status) git ct (commit) git br (banch) git co (checkout) git back
(reset --hard) git last (log -1 head) git last2 (log -2 head)

------
dave1010uk
I've aliased git to "g" in bash and set up aliases in my ~/.gitconfig [1].

Reducing "git" to "g" or "status" to "st" doesn't speed up my workflow much.
The real gains come with aliasing something like this:

    
    
      git --no-pager log --oneline --graph -n 18 --decorate
    

[1] <https://github.com/dave1010/scripts/blob/master/gitconfig>

~~~
wpb3
Agreed. What I would really like to see is alias' to handle git operations
that you typically would have a slim chance of remembering on your own. For
example, reverting changes: [http://stackoverflow.com/questions/927358/git-
undo-last-comm...](http://stackoverflow.com/questions/927358/git-undo-last-
commit) <http://stackoverflow.com/questions/348170/undo-git-add>

------
darkxanthos
Save me hours? Over a year maybe. Trust me, this isn't the biggest time suck I
have. __stares intently at HN __

------
stephen
Posted a comment on the site, but to me the real win comes when you add grep
to your aliases. That saves a ton of keystrokes, assuming you have deep
directories in your project:

<http://www.draconianoverlord.com/2010/03/04/git-config.html>

------
dlsspy
I don't save time by having non-standard commands that aren't available on all
of my machines.

------
micampe
If you use git-svn, this makes _git svn dcommit -n_ actually useful to review
what you are going to commit:

    
    
        [alias]
            svndiff = !"$(git svn dcommit -n | grep "diff-tree" | sed 's/diff-tree/git diff-tree --color=auto -p/')"

------
flocial
Not to mention editor/IDE integration that streamlines common workflows making
the need to use the shell for git commands less likely

------
mccutchen
The big downside of these (for me) is that they don't let me use the great
bash completion that git (optionally) provides.

~~~
sanderjd
They can!

    
    
      # Make git completion work with aliases
      complete -o default -o nospace -F _git_checkout gco
      complete -o default -o nospace -F _git_rebase grb
      complete -o default -o nospace -F _git_branch gbdf
      complete -o default -o nospace -F _git_branch gbd
      complete -o default -o nospace -F _git_diff gd
      complete -o default -o nospace -F _git_log gl
      complete -o default -o nospace -F _git_log glp

------
MBlume
git aliases > bash aliases, since completion still works.

Here's mine: <https://gist.github.com/916019>

