Installing & Using Github for Version Control on Mac OS

Install Git via the Command Line

The command line is a text-based way to tell you computer what to do. Most of the time, we interact with our computer by clicking on apps, files, icons, etc and use our mouse to input the “commands” that tell the computer what to run (and display) next. The command line does essentially the same thing, but instead of clicking, you are typing the commands.

On a Mac, the command line is accessed by opening the app Terminal that comes pre-installed on your computer.

  1. Open Terminal in finder -> applications -> terminal.app

    You should see something like this, but with your computer’s information:

  1. To check if you already have Git installed, type the command:

    git —version

If you have Git already installed, it will show “git version 2.50.1 (Apple Git-155)” (or whichever version is installed on your computer). If you already have Git installed, you can skip step 3.

  1. If you do not have Homebrew installed already, install it by copying and pasting the following code into Terminal:

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

Homebrew is used to install Git. Link to Homebrew Installation & Documentation for more information.

  1. You will be prompted for your password. Type in your main computer login password and press enter. It may not look like you’re typing anything - Terminal is just hiding it because it’s a password, but if you type in your password and hit enter, it will begin to load installation scripts.
  2. After the initial installation scripts run, press RETURN/ENTER to continue (you will be prompted to do so in Terminal as well). This will finish installing Homebrew and when done, will display instructions to Run commands to add Homebrew to your PATH under NEXT STEPS:

Copy and paste the code shown in your Terminal and press enter to run.

  1. Install Git by copying and pasting this code:

    brew install git

Terminal will begin to install the most recent version of git.

  1. Last, install Git Credential Manager (GCM) so that you can easily access your Github account/repositories from Terminal. This enables you to be able to type in your Github account login information without needing a Personal Access Token to access your Github repositories (trust me… this way is much easier!)

Type the following code and run it:

brew install --cask git-credential-manager

You may be prompted to type your computer login information again (i.e. your main computer password) - if so, enter your password and press enter for the installation to begin. This is what you should see when you have finished installing GCM:

Yay! You have successfully installed Git to your Mac and are now ready to use it to collaborate and manage your code.

Version Control - Using Git in Terminal & R Studio

Git connects to GitHub, a website (and available as a desktop app) where you can create and collaborate on projects by creating repositories. A repository can be public or private and you can create a new repository to store the contents of your project - i.e. code scripts, source files (CSVs, PDFs, .json, etc), and information about your repository in a README file. Link to README information

  1. If you do not already have GitHub account, then navigate to github.com and create a free account.

  2. Log in to your account and click “Repositories” and then “Add new”

    This will allow you to create a new Repository with options to make it private or public, add a README file, and other general settings. This Repository is stored on your github account and can be accessed on github.com or via Terminal. Alternatively, R Studio also has a “Terminal” option to the right of the “Console” tab within the console - this allows you to run Terminal commands directly in R, instead of separately in the Terminal app. You can use this method for the next steps, or if you prefer to have Terminal open separately, that works the same way.

For more information about repositories (and more helpful Github tools), use this link: https://docs.github.com/en/repositories/creating-and-managing-repositories/about-repositories

  1. Open R Studio and in the console, run: install.packages("remotes")

This will allow you to remotely access your Github repository from R Studio directly in the Terminal tab within the console. You may already have this installed in R by default, but always good to check!

  1. Open Terminal again. Run the code pwd to print your “working directory”. Essentially, this will show you what folder your Terminal currently is viewing. Typically, it defaults to your computer hard drive. You will need to change your working directory so that when we copy the Github repository to your computer, it saves the contents of the repository to this specific location on your computer (i.e. a folder, Documents, Desktop, a server, etc), unless you wish to copy the repository directly to your hard drive.

  2. In Finder, navigate to the folder that you want to save the Github repository in. For example, if I wanted to add the repository to my “Documents” folder, I would navigate to that in Finder, right click the name of the folder and hold down the “option” key after you right click. There is now an option to “Copy as Path Name”. Copy the file path of the desired folder you wish to add the Github repository to.

  3. Return to Terminal and use the command cd to “change directory” and paste the Pathname you copied in quotes next to the cd command. This code will update your working directory:

    cd "PASTE YOUR DESIRED FILE PATH HERE"

  4. Back to github.com and your new repository - on the main page, right click on the green “Code” menu and click “Local”. Copy the URL. The below screenshot shows what you should see in Github:

  5. In Terminal, type git clone and paste the link you copied from Github next to the command:

git clone "yourRepoLink.git"

  1. You will now get a popup with GitHub Sign In options. Choose “Sign in with your browser”

You can now log in to Github in your browser and then select authorize so that your Github login information is now cached (stored) in your computer for future use.

Now that you are logged into Github, the git clone command you typed earlier will “clone” (copy) your entire Github repository to your working directory! If you check the folder of your working directory in Finder, you will now see the Github repository contents. You can now open whichever file you wanted to use from your Github repository in the applicable software (i.e. RStudio or Excel) and begin working on it.

Git “Push” and “Pull” to apply file/repository changes:

  1. Pretend that you are done working for the day on a file in your repository. Save the changes as you normally would (i.e. command+save or pressing the save icon). Now, in terminal run the following code with your file name:

    git add "file name that you would like to save changes to"

Or, if you made changes to multiple files in the repository, you can simply run git add .

This will add all the changes to the repository that have been made since you last cloned it.

  1. In Terminal, “Commit” your changes and describe (briefly) what changed/the purpose of this “commit”:

    git commit -m "describe changes made"

  1. In terminal, run the command git push. This will now “push” the changes that you have committed to the Github repository! The description your wrote in the git commit message in Step 13 will appear on Github in your repository next to the file that you changed. For example, Sarah updated the README.md file 13 minutes ago and described the edits in the commit message as “Sarah deleted duplicate 6914 priorities section”:

    1. Now that you have already cloned this repository, the next time that you need to “pull” from the repository - i.e. if someone else made changes to the repository since you last “pushed” to Github, then you will need to “pull” the updates from Github to the working directory of the repository on your computer.

    To do this, open Terminal, ensure the working directory is set to where the repository was previously stored on your computer, and run the following code: git pull

CONGRATULATIONS! You can now clone a repository, commit and push your changes back to Github, and pull any new changes from Github to your computer. This is an incredibly useful tool for project collaboration, management, transparency, and documentation as you are able to track each change made to files in your repository over time.

Appendix: Helpful Github & Coding Resources:

This guide was created by Grace Rossi on 03/10/2026 and most recently updated on 03/11/2026