Why Git Alias
Tags: git, alias, share
Published: 2018-08-02 05:08:58

---
title: Why Git Alias
published: true
description: 
tags: git, alias, share
---

I've been using git aliases for a while now. People have seen me using them, asked me, I explained, encouraged them to use it too and failed. Why? 

Perhaps my convincing powers is not that effective so I will try to appeal one more time.


## Git Alias

Git aliases are shorthand for git commands. Just add it to your `~/.gitconfig`.

```
[alias]
    st = status
    ch = checkout
    chb = checkout -b
```

Now, instead of typing `checkout -b`, you can just type `chb`.
```
git checkout -b bug12345
git chb bug12345
```

Cool, right? So, what else?


### Why Git Alias?

#### It's cool!

Yes, I've said it again. But isn't it just cool, really? Being able to accomplish multiple commands in one go. While others execute git commands one by one, you take a shortcut and use aliases. Doing something out of the traditional. Gotta admit, it feels badass to use git aliases at times (*especially when pair programming*)

![alt text](https://media.giphy.com/media/MM0Jrc8BHKx3y/giphy.gif)


#### It saves time

I don't think I need to emphasize this more. You can stage, commit then push your changes in few clicks. Which will save you more or less 10 seconds, considering you commit roughly 10x a day, can save you at least 2 minutes a day. Which you can use to fix your coffee, go to comfort room, update your code reviewer or just stretch and have a quick nap.

![alt text](https://media.giphy.com/media/l6gZ4YYesTutW/giphy.gif)


#### My git aliases

Here are some aliases that I frequently use. All, I share [here] (https://github.com/devcamilla/gitalias/blob/master/.gitconfig).

```
[alias]
    #current branch
        me = !git rev-parse --abbrev-ref HEAD
    #publish
        up = !git push origin -u $(git me)
    #unpublish
        down = !git push origin --delete $(git me)
    #stage all then commit with message
        acm = !git add . && echo 'Staged all changes, if any.' && git commit -m $message
```

I recently discovered the `fixup` git alias [here] (https://blog.filippo.io/git-fixup-amending-an-older-commit/). It lets you amend your staged changes to a specific commit.

```
fixup = "!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f"

```
To use, just provide a few SHA-1 hash of the commit you want to amend to.

```
git fixup d670460b
```
Then voila! Your recent staged changes should be fixed up to that commit. 

There are lots of possibilities you can do with aliases. For one, when resolving rebase conflicts, I also use git alias to open *TortoiseGit* and execute *diff* on my source files. It's up to us to discover these possibilities.


### Why Not Git Alias

X: So what's the git command for publishing branch again?
Me: `git up` 
X: not a git command
Me: (*Remembers it's an alias*) Oh, wait. Let me check.

Okay, because you use aliases it's normal to forget the original commands. There's no escaping that. But don't worry I got your back. There's also a git alias for that. 

```
# list aliases
    la = !git config -l | grep alias
```
Use `git la` to list all your aliases and the corresponding commands. Great way to hack around using git aliases.


## Conclusion


I hope I introduced Git Alias enough to make you try it. Just want to share the bliss of using it. Hope you also find it useful in your daily programming experience.

For others using it too, care too share your favorite aliases? What do you like the most about it?

For others who don't, why not?