Whenever I am setting up my development environment on a fresh macOS install, one of the first things I need to do is configure Git to work with my GitHub account. Looking up all the steps required to do so continues to be an absolute pain each time. I’m writing this post to collect this information in one place, and publishing it in the hopes that someone else may find this useful.
This guide will cover the following aspects:
- Setting up user details
- Authenticating with 2FA enabled
- Ignoring .DS_Store files everywhere
- Enabling GPG commit signing
Authenticating
Update: GitHub CLI now supports authentication with gh auth login
, which I would recommend using instead of the below instructions.
First, you’ll need to configure your name and email address in Git. If you’ve enabled the GitHub setting to keep your email address private, make sure to use your @users.noreply.github.com address here. I prefer to configure these settings globally, but you can also do this on a per-repository basis (omit the --global
flag).
git config --global user.name "Your Name"
git config --global user.email you@example.com
When you try to push to a GitHub repository or clone a private repo, Git will prompt you for your credentials. If you aren’t using two factor authentication, then you can enter your GitHub username and password as usual. If you are using 2FA (you probably should be), then you’ll need to generate a personal access token.
…