Setting Up Git and GitHub on Mac
Introduction
Welcome to the guide for setting up Git and GitHub on Mac. This guide assumes no prior coding or Git experience.
We will cover:
- Downloading and installing Git.
- Verifying the installation.
- Generating an SSH key.
- Adding the SSH key to GitHub.
- Linking the SSH key with RStudio.
Step 1: Install Git
Open the Terminal application on your Mac.
Check if Git is already installed by running:
git --version
If Git is not installed, you will see a prompt to install the Xcode Command Line Tools:
- Click Install and follow the on-screen instructions.
Once installed, verify Git by running:
git --version
- You should see a version number, e.g.,
git version 2.x.x
.
Step 2: Generate an SSH Key
Open the Terminal application.
Run the following command:
ssh-keygen -t ed25519 -C "your_email@example.com"
- Replace
your_email@example.com
with your GitHub email address.
When prompted:
- Press Enter to save the key to the default location.
- (Optional) Enter a passphrase for added security.
Your SSH key will be saved to a default location, e.g., /Users/YourName/.ssh/id_ed25519
.
Step 3: Add the SSH Key to GitHub
- Display your public SSH key:
Run the following command in Terminal:
cat ~/.ssh/id_ed25519.pub
Copy the output (Cmd + C).
- Log in to your GitHub account.
- Go to Settings > SSH and GPG keys.
- Click New SSH key:
- Title: Give your key a name (e.g., “My Mac”).
- Key: Paste the copied key into the text box.
- Click Add SSH key.
- Confirm your password if prompted.
Step 4: Test the SSH Connection
Open the Terminal application.
Run the following command:
ssh -T git@github.com
If successful, you will see a message like:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
- If there’s an error, check that the SSH key was added correctly.
Step 5: Link SSH Key with RStudio
- Open RStudio.
- Go to Tools > Global Options.
- In the left-hand menu, click on Git/SVN.
- Check the box labeled Enable version control interface for RStudio.
- Under the Git executable field, ensure the path points to the Git installation, e.g.,
/usr/bin/git
.
- Click Apply and then OK.
Step 7: Clone a Repository in RStudio
- Go to your GitHub repository.
- Click the green Code button and select SSH.
- Copy the SSH link (e.g.,
git@github.com:username/repo.git
).
- In RStudio, go to File > New Project > Version Control > Git.
- Paste the SSH link into the Repository URL field.
- Choose a directory to save the project and click Create Project.
Congratulations!
You have successfully:
- Installed Git.
- Verified the installation.
- Created and added an SSH key to GitHub.
- Linked the SSH key with RStudio.
You are now ready to use the Git GUI in RStudio to manage your projects and collaborate effectively!