I figured this would be a good place to make a quick guide that I can conveniently refer to when needed.
Table of Contents
First you will need to install Homebrew. The instructions for that can be found here.
Once all the dependents Homebrew has been installed, you can install Homebrew with the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Installing & Configuring git
Although macOS comes with Git preinstalled, you can update Git by running the following command:
brew install git
Next we need to configure Git to match the information on your GitHub account. This can be done by running the following commands:
git config --global user.name "Your Name" git config --global user.email "firstname.lastname@example.org"
You can verify the config above by running:
git config --get user.name git config --get user.email
You can then set the default branch to
Main (recently standardized) by running:
git config --global init.defaultBranch main
3. Connecting Git to GitHub with a SSH Public Key
We are now ready to create a public SSH key and connect Git to your GitHub.com account!
First, create a Git SSH key by running the following command (It’s important that your email matches your GitHub email.):
ssh-keygen -t ed25519 -C <youremail>
Once that has been done, you can then copy the SSH public key to your clipboard by running:
pbcopy < ~/.ssh/id_ed25519.pub
Now you can log onto GitHub.com, click on your profile picture, then click Settings, and SSH and GPG Keys, or by clicking here. Once there, click
New SSH Key, enter a title that identifies the device you’re adding the SSH key for and paste the contents into the key section.
You can then test your SSH key by running
ssh -T email@example.com
If successful, you’ll see a message like:
> Hi <em>username</em>! You've successfully authenticated, but GitHub does not > provide shell access.
One response to “Setting Up Git & Connecting to GitHub on macOS”
[…] every time you make changes. If you have have your SSH public key set up as described in this article, then you’ll want to use the SSH […]