
Show HN: Git alias commands and shortcuts - jph
https:&#x2F;&#x2F;github.com&#x2F;GitAlias&#x2F;gitalias<p>Do you use git? I have a big list of alias commands and shortcuts that I&#x27;m sharing on GitHub.<p>I&#x27;m seeking suggestions and feedback now, and also seeking pull requests to improve the code.
======
petetnt
If you are a oh-my-zsh user, the Git plugin has tons of aliases ready to use:
[https://github.com/robbyrussell/oh-my-
zsh/wiki/Plugin:git](https://github.com/robbyrussell/oh-my-
zsh/wiki/Plugin:git)

~~~
jph
Thanks! I'll add this to the README now.

------
alekratz
I do something similar to this, except I just use my shell's alias do to this.
e.g., alias gits="git status".

If you're like me and have a weird habit of just typing stuff into the
terminal during the day, "gits" (or "git s" if you use OP's stuff) will become
one of your most typed commands.

~~~
unhammer
For me, it's bash functions "st" (or "sq" to skip untracked); I also made them
such that they DTRT in svn, hg, darcs as well. Probably my most used commands
:-)

------
brudgers
Direct link:
[https://github.com/GitAlias/gitalias](https://github.com/GitAlias/gitalias)

------
kristjan
But you're still typing `git` every time!

    
    
        alias g=git
    

I've got my Git configs up at
[https://github.com/kristjan/.dotfiles/blob/master/.gitconfig](https://github.com/kristjan/.dotfiles/blob/master/.gitconfig)
if you'd like to sift through them. The very most common, like `git status`,
get their own Bash aliases too
([https://github.com/kristjan/.dotfiles/blob/master/.aliases#L...](https://github.com/kristjan/.dotfiles/blob/master/.aliases#L37-L52)).
Who can be bothered to type a space?

~~~
mathgeek
Not sure if I'm in the majority or minority here, but I actually prefer that
the main command (git in this case) not be shortened. The rest of the options
are where I find aliasing to be useful. Only because as the numbers of aliases
you use grows, it becomes more likely that you'll overwrite your single-letter
aliases.

~~~
kristjan
Certainly everything in moderation - I only give letters to commands I
literally type hundreds of times daily. Over the past 10 years, I've
accumulated 5:

    
    
        b=`bundle exec`, though this is becoming less often used and I may remove it
        d=dotenv to easily wrap a command in environment variables 
            (https://github.com/bkeepers/dotenv)
        g=git
        h=hub (GitHub's extensions to Git)
        j=autojump to move to common directories using just a few characters
            from their name (https://github.com/wting/autojump)

------
sdegutis
Related: if you use Emacs, look into Magit, it's amazing.

[https://magit.vc/](https://magit.vc/)

~~~
jph
Thanks, I'm adding Magit to the README now.

------
wuthefwasthat
aliases for opening files, which i find quite useful

    
    
      # open file by name
      op = "!f() { $(git editor) $(git ls-files | grep -i \"$@\"); }; f"
    
      # open currently edited (unstaged) files
      eop = "! $(git editor) $(git ls-files --modified)"
    
      # open files for conflicts (good for rebase/cherry-pick/merge)
      mop = "!f() { $(git editor) $(git diff --name-only --diff-filter=U); }; f"
    
      # open files present in diff
      dop = "!f() { $(git editor) $(git diff --name-only $@); }; f"
    
      # grep and open files containing
      gop = "!f(){ $(git editor) $(git grep --name-only \"$@\"); }; f"
    
      # "show and open" commit
      shop = "!f() { $(git editor) $(git show --pretty=\"format:\" --name-only $1); }; f"
    
      editor = config --get core.editor
    

I wrote a bit about them here:
[https://wordpress.com/post/wuthefwasthat.wordpress.com/19](https://wordpress.com/post/wuthefwasthat.wordpress.com/19)

And all my aliases here:
[https://github.com/WuTheFWasThat/dotfiles/blob/master/.gitco...](https://github.com/WuTheFWasThat/dotfiles/blob/master/.gitconfig)

~~~
brbsix
That looks like some sort of internal WordPress link. I think you mean:

[https://wuthefwasthat.wordpress.com/2016/06/18/git-open-
alia...](https://wuthefwasthat.wordpress.com/2016/06/18/git-open-aliases/)

------
w4rh4wk5

        c = checkout
        d = diff
        ds = diff --staged
        l = log --all --graph --oneline --decorate
        s = status --short --branch
        g = grep --break --heading --line-number
        ff = merge --ff-only
        puff = pull --ff-only
        purr = pull --rebase
        mnc = merge --no-ff --no-commit
        ignore = update-index --assume-unchanged
        unignore = update-index --no-assume-unchanged
        ignored = !git ls-files -v | grep '^[[:lower:]]'

------
felipesabino
Hey, nice usage of "$(git branch-name)" in the commands, I haven't thought
about that

I have been keeping my gitconfig public [1] it's been a while and I will
definitely use this repo as another source to increment it :)

[1]
[https://gist.github.com/felipesabino/6391408](https://gist.github.com/felipesabino/6391408)

~~~
jph
Thank you! I'm adding your link to the README now.

------
embiggen
How can you justify mapping 'p' to 'pull' rather than 'push'?

I applaud the effort and think it's unfortunate the value add seems so
marginal here. This type of thing boils down to mostly personal preference.

~~~
jph
I polled several hundred people during three years. :)

In practice, my teams tend to get the most value-add by using purpose-driven
aliases for typical pull/push needs.

For example, the alias `publish` will push a local topic branch up to a
continuous delivery server.

------
michaelmior
I'm personally a big fan of SCM Breeze[0]

[0]
[https://github.com/ndbroadbent/scm_breeze](https://github.com/ndbroadbent/scm_breeze)

~~~
jph
Cool, thanks, I'm adding that to the README now.

------
seletskiy
I've got more insane and effective solution:
[https://github.com/seletskiy/zsh-context-
aliases](https://github.com/seletskiy/zsh-context-aliases)

So, aliases will change depending on the directory you're in.

And, instead of typing `g s` or `gs` to get `git status` you simply typing
`s`.

------
marcuskaz
My favorite:

    
    
        unfuck = reset HEAD --hard

~~~
jph
Ha! That's hilarious. I'll add something like that, with slightly more polite
language. :)

------
BlakePetersen
DUDE! Just link the github URL directly next time -- not only should this sort
of discussion be done and persist on GH, not a random HN comment thread, but,
for whatever reason, iOS won't let me copy that link so I have to type it in
manually. Which I won't do.

Poor form, buddy. Poor form.

