DEV Community

John Leavell
John Leavell

Posted on

How to Setup Your GitHub Repository (Mac Version)

Hey there!

So, I was setting up my laptop during my apprenticeship and ran into a bit of a snag. But don't worry, it's all good now. I mean, what's a tech setup without a few bumps in the road, right? Anyway, let me tell you a little bit about what happened...

How to Setup Your GitHub Repository (Mac Version)

Prerequisites:

  • Git
  • GitHub account
  • Xcode command line tools
  • Homebrew

Installation Steps:

  1. Install Xcode Command Line Tools In the terminal, type:
xcode-select --install
Enter fullscreen mode Exit fullscreen mode

Follow the instructions to install Xcode Command Line Tools.

Note: This process can take some time.

2. Check Xcode Installation

To check if Xcode Command Line Tools was installed correctly, type:

xcode-select -p
Enter fullscreen mode Exit fullscreen mode

You should see:

/Library/Developer/CommandLineTools
Enter fullscreen mode Exit fullscreen mode

3. Install Homebrew

Check if Homebrew is installed by typing:

brew
Enter fullscreen mode Exit fullscreen mode

If Homebrew is not installed, follow the script on the Homebrew website to start the installation process:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Follow the prompts and enter your password when prompted.

Note: This process can take some time. So grab a coffee and come back.

Check if Homebrew was installed correctly by typing:

brew doctor
Enter fullscreen mode Exit fullscreen mode

You should see:

Your system is ready to brew.
Enter fullscreen mode Exit fullscreen mode

4. Configure Git

Install Git and GitHub using Homebrew by typing:

brew install github
Enter fullscreen mode Exit fullscreen mode

Check if Git was installed correctly by typing:

git --version
Enter fullscreen mode Exit fullscreen mode

You should see:

output /usr/local/bin/git
Enter fullscreen mode Exit fullscreen mode

Next, define your Git user by typing:

git config --global user.name "Your name here"

git config --global user.email "your_email@email.com"
Enter fullscreen mode Exit fullscreen mode

This will be added to your .gitconfig file.

GitHub recommends using HTTPS to push code to your repositories. To prevent Git from asking for your username and password every time you push a commit, you can cache your credentials by running the following command:

git config --global credential.helper osxkeychain
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can use the SSH method.

5. SSH Config for GitHub

Generate a new SSH key by typing:

ssh-keygen -t rsa -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

Add your SSH key to the ssh-agent by running:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

If you're running macOS Sierra 10.12.2 or later, you'll need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.

Check if your ~/.ssh/config file exists by typing:

open ~/.ssh/config

If it doesn't exist, create the file by typing:

touch ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Then, modify the file to contain the following lines:

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Add your SSH private key to the ssh-agent and store your passphrase in the keychain by running:

ssh-add -K ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Finally, add your SSH key to your GitHub account.

Conclusion
Congratulations! You've now set up your GitHub repository on your Mac. Good luck with your projects!

Top comments (2)

Collapse
 
camillearce profile image
camille-arce

Thanks for the guide, John.

Collapse
 
castnay profile image
nayla_techprep

Super helpful, John. Thank you for posting this!