What Do I Put in My .gitconfig?

Where do I put my .gitconfig?

When I spin up a dev environment, the first thing I want to do is drop in my user .gitconfig file, and I always forget where to put it. BTW, you just drop it in your home folder ~/.gitconfig, so on my PC C:/Users/giulianat/.gitconfig, and on my mac /Users/giulianat/.gitconfig. This is also where your user-level .gitignore file goes (more on this later).

You can find my entire .gitconfig file on GitHub.


Some things you might just want to abbreviate

ch = checkout
br = branch
ci = commit
st = status

Some things you might just want to forget about the options

brename = branch -m

I misspell my branch names ALL 👏 THE 👏 TIME and I always forget how to rename them, so I store it into an alias.

  • To Use: git brename new_branch_name
  • Docs: branch -m
cm = commit -am

I hardly ever have unstaged files when I go to commit, so I have an alias that stages all of my files and allows me to write a message.

  • To Use: git cm "Commit message"
  • Docs: -a and -m
last = log -1 HEAD

I often forget what I’m doing and want to check the latest commit on the current branch.

lg = log --oneline --no-merges

Before I submit a PR, I like to review the commit log to make sure it’s nice and tidy for my code reviewers, and I like to exclude merge commits because they’re generally just noise to me. This one will print commits in a single line, showing only the commit hash and the commit message. I use lg so I know it’s a compact log.

diff-br = diff --shortstat develop..HEAD

Another thing I like to do before publishing a PR, is take a look at all of the things I’ve changed on my current branch.

visual = !gitk

Sometimes, I’m need a visual of my git commit history, especially when there’s a lot of merging going on. This will pop open a repo browser with a pretty neat view of your branches.

  • To Use: git visual
  • Docs: gitk
pull = pull --all --prune

oOOOooo 😍 this one is my absolute fave! I like to pull all of my branches down all the time. It keeps me from having to rebase later on if I switch branches. This also prunes any local branches that anyone deleted on remote.

NOTE: pull will merge remote branches into your local one. You can also tack on --rebase here to prevent gross merge commits in your commit log, or you can replace pull with fetch, which won’t merge.

push = push -u origin HEAD

I freakin’ hate when I create a new branch, and I go to push and I get the set upstream branch error. So I added this in there so I never have to think about it again. Pairs well with the push.default setting below.

  • To Use: git push
  • Docs: -u
destroy = reset HEAD --hard

This alias gets the Miss Congeniality award. Often, I mess with a lot of files and then scrap the entire thing because I did it totally wrong. This will destroy revert all of my staged AND unstaged changes.

  • To Use: git destroy
  • Docs: –hard


    name = Giuliana Taylor

This is so that your GitHub author name isn’t your email. I think it presents more professionally. Docs

    rebase = true

I would like to give this git setting a standing ovation. I have a very strong preference for rebasing over merging, and this setting tells git to rebase anytime I pull. Docs

    autoStash = true

I absolutely hate when git aborts my rebase because I have unstashed changes. This config stashes your changes, rebases, and then pops the stash automatically. Docs

    default = current

This config also prevents the set upstream branch error you get when pushing a new branch by auto-creating a remote branch with the same name. Docs

    tool = default-difftool
    prompt = false
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE
    prompt = false

Find you a diff tool you really like, and then set it here so you never have to see an ugly diff tool ever again. I personally like VSCode’s diff tool (more on this).

I also hate being prompted every time, so I’ve turned that off.

    tool = default-difftool

This is along the same lines, only you’re telling git which diff tool to use for merges. Docs

    excludesfile = ~/.gitignore

You’ll want a personal .gitignore file. This is where you should exclude IDE generated files. This tells git where your file is located. Docs

I know that was a lot but I hope that helps flatten your git learning curve!

Written on June 17, 2020