How to set up Github on MacOS?

Syed Muhammad Faheem
3 min readJun 10, 2023

--

Introduction

Git is a powerful version control system that allows developers to efficiently manage their code and collaborate with others. Before making use of Git, it’s essential to check if it’s already installed on your system. In this guide, lets walk through the process of verifying your Git installation and then set up authentication using SSH keys to securely interact with GitHub repositories.

Step 1: Checking Git Installation

To check if Git is installed on your system, open your terminal or command prompt and run the following command:

git --version

If Git is installed, you will see its version number displayed; otherwise, you’ll need to install Git before proceeding with the next steps.

Step 2: Generating SSH Key

SSH keys provide a secure way to authenticate your device with Git and GitHub. To generate an SSH key, follow these steps:

  1. Open your terminal or command prompt and run the following command, replacing your_email@example.com with your GitHub account email:
ssh-keygen -t ed25519 -C "your_email@example.com"
  1. You will be prompted to choose a location to save the key. The default location is usually ~/.ssh/id_ed25519. You can leave it as is or specify a different path.
  2. Optionally, you can set a passphrase for added security. This passphrase will be required every time you use the SSH key.

Step 3: Starting the SSH Agent

The SSH agent manages your SSH keys and allows you to use them without having to enter the passphrase each time. To start the SSH agent, run the following command:

eval "$(ssh-agent -s)"

Step 4: Configuring SSH for GitHub

Next, we need to create or open the SSH configuration file ~/.ssh/config. You can use any text editor you prefer; we'll use VIM as an example:

vim ~/.ssh/config

In the config file, add the following lines:

Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519

Save and close the file.

Step 5: Adding the SSH Key to the Agent

Now, we’ll add the SSH key to the SSH agent, and if you’re using macOS, we’ll also add it to the Apple Keychain for secure storage. Run the following command:

ssh-add -K ~/.ssh/id_ed25519

Step 6: Creating a GitHub Repository

With Git properly authenticated using SSH keys, you can now create a new repository using the GitHub interface. Once the repository is set up, copy the SSH link to the repository.

Step 7: Connecting the Repository

To connect your local repository with the remote GitHub repository, run the following command, replacing ssh-link-to-repo with the copied SSH link:

git remote add origin 'ssh-link-to-repo'

Step 8: Commit and Push Changes

You’re all set! Now you can add and commit changes to your local repository as usual, and when you’re ready to push the changes to GitHub, run:

git push origin master

Conclusion

Congratulations! You’ve successfully set up and authenticated Git with SSH keys, allowing you to securely interact with your GitHub repositories. By using SSH keys, you enhance the security of your version control system and make your development workflow smoother.

Happy coding!

--

--

Syed Muhammad Faheem

"I live my life by writing". Follow me for more articles on trending technological topics.