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.
Open Terminal in finder -> applications -> terminal.app
You should see something like this, but with your computer’s information:
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.
/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.
Copy and paste the code shown in your Terminal and press enter to run.
Install Git by copying and pasting this code:
brew install git
Terminal will begin to install the most recent version of git.
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.
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
If you do not already have GitHub account, then navigate to github.com and create a free account.
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
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!
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.
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.