# Git


## Useful Defaults

**Fast Forward Only:** Avoid merge commits when possible by using the
`--fast-forward` strategy for `git pull`. This can be set in your git config
with:

```sh
git config --global merge.ff only
```

**Enable Autocorrect:** Allow git to autocorrect mistakes after a timeout. For
example, running `git commt` or `git psuh` will automatically "do the right
thing" after a specified timeout.

```sh
git config --global help.autocorrect 20
```

The unit of this config setting is tenths of a second, so a setting of 20 means
that git will automatically run what it thinks the correct command is after 2
seconds. (See
[this post](https://andy-carter.com/blog/auto-correct-git-commands) for a bit
more detail.)

## Tips

**Pull with `--autostash`**: If you frequently see errors when running
`git pull` related to unstaged changes, you can have your working directory
automatically stashed and re-applied using `--autostash`:

```sh
$ git pull
error: cannot pull with rebase: You have unstaged changes.
# 😥

$ git pull --autostash
Created autostash: 798c4a2
Current branch main is up to date.
Applied autostash.
# 😀
```

## Longer Posts

-   [Branchless Git](/blog/2021/12/07/Branchless-Git/) is my preferred git
    workflow.
-   [Features of Excellent Code Review Tools](/blog/2021/10/17/Features-of-Excellent-Code-Review-Tools/)

