⚡ How to become faster in Git CLI
Tags: github, git, productivity, tutorial
Published: 2020-07-20 16:36:04

### 👋🏻 Hey, there

First of all, get your favorite drink, prepare your `.gitconfig`, and come with me through this huge valley called "Git"...

---

Git is constantly present in our routine as developers, and a good approach to use this tool is essential. For this case — and any else — there is **[Git Alias](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases)**.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0bej4uy17qeu125alesw.png)

# 🤔 What is it?

A **Git Alias** is simply as a shortcut to other command used in Git CLI. In one fast and abstract comparation, the **complete command from Git** looks like the functionality of Copy something using the right button from mouse, and a **Git Alias** is the `Ctrl + C` shortcut.

# ⁉ Why?

Because you are able to save time using this shortcuts, and with specifics settings some commands that are naturally long will be reduced to one keyword. 

With a simple example, you will be able to turn this:

```bash
git remote add origin https://github.com/user/repository.git
```

Into this:

```bash
git remo https://github.com/user/repository.git
```

⚠ In this case, I have set `remo` as a alias from `remote add origin`, **but the name of it can be any word you wish**.

# 🚀 Here we go...

## Find the configuration file

First of all, it is necessary to find the configuration file from Git, in your machine.

### Windows

```bash
# To set the config for one user only
C:\Users\{your_user}\.gitconfig

# To set the config for all the users from machine
C:\Program Files\Git\etc\gitconfig
```

### Unix

```bash
# To set the config for one user only
~/.gitconfig
# or
~/.config/git/config

# To set the config for all the users from machine
/etc/gitconfig
```

## Set the Aliases

Open the file with an IDE by your preference, and start to set shortcut for commands you need. Before set the first keyword, type `[alias]`, indent, and then you are able to set shortcuts. For example:

```bash
[alias]
  ad = add .
  remo = remote add origin
  rem = remote add
```

### ⚡ Aliases I use

To save time, you can copy and paste the aliases I use, and then change each of them by your preference.

```bash
[alias]
  ad = add .
  remo = remote add origin
  rem = remote add
  ci = commit -m
  pm = push origin master
  po = push origin
  plm = pull origin master
  pl = pull origin
  co = checkout
  cm = checkout master
  cb = checkout -b
  st = status -sb
  sf = show --name-only
  lg = log --pretty=format:'%Cred%h%Creset %C(bold)%cr%Creset %Cgreen<%an>%Creset %s' --max-count=30
  incoming = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' ..@{u})
  outgoing = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' @{u}..)
  unstage = reset HEAD --
  undo = checkout --
  rollback = reset --soft HEAD~1
```

# 🏁 Conclusion

Git Alias is a huge friend of our productivity, and surely will help you in your daily commits. For more information about this tool, check the [official documentation](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases), or the [complete guide](https://git-scm.com/book/en/v2) of Git.

*[This code](https://gist.github.com/cristianprochnow/5f51877016e42daef1822b2e8a7e4e3f) I use is an adaptation from [this one](https://gist.github.com/diego3g/2b563e54e82bed5530d8346b89a701ab).*