# Git command aliasing

We can configure Git commands for various purposes:

## Shortening Git commands

Instead of typing out a command line `git status` entirely, we can configure our command line so that we can just type `git s` (or `git whatever`):

```bash
$ git config --global alias.s status
$ git s
```

The [Git manual](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases) recommends other aliases:

```bash
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
```

## Combining Git commands

This [answer to a Stack Overflow question](https://stackoverflow.com/questions/4298960/git-add-and-commit-in-one-command) combines `git add` and `git commit` into one `git add-commit`:

```bash
$ git config --global alias.add-commit '!git add -A && git commit'
$ git add-commit -m 'my commit message'
```

Combining the above two, we can do something like:

```bash
$ git config --global alias.ac add-commit
$ git ac -m 'my commit message'
```

Thus, we can generalize the format as:

```bash
$ git config -global alias.{alias} {command}
$ git {alias} [flags]
```

## Other examples

### Configuring a "push to origin" command

Short for `git push origin branchname` (push to the cloud!)

```bash
$ git config --global alias.pom 'push origin branchname'

# pushes to branch named branchname
$ git pom
```

### Configuring a "checkout new branch" command

Short for `git checkout -b {branch-name}` (check into a new branch)

```bash
$ git config --global alias.cob 'checkout -b'

$ git cob anybranchname
```

Enjoy!
