Skip to content

Git and GitHub

Eric Marty edited this page Sep 12, 2023 · 12 revisions

Page Editor: @allopole
To request edits to this page, open an issue, and tag @allopole


Creating a GitHub Repository for your Drake Lab Project

  • Log in to GitHub.
  • Click on the "New" button.
  • Select DrakeLab as the owner.
  • Enter a repository name following our project naming conventions.
  • Enter the full project name as the Description.
  • Select Private
  • Leave Initialize this repository with a README unchecked if you will be adding your protocol as REAMDE.md later.
  • Leave Add .gitignore: None and Add a license: NONE for now. You can add these later if you need them.
  • click Create Repository

Add Optional Topic Tags

After you have created your repository, you may add Topic Tags to help people search for your project by topic. To add topics, click on manage topics under the description:

...

List of suggested topics:

  • ews
  • zika
  • malaria
  • simulation
  • We will eventually have a full list of topics here

If you don't have Git on your computer:

  1. Download it and install it from here: https://git-scm.com/downloads

  2. In RStudio, go to Tools > Global Options Click Git/SVN Click Enable version control interface for RStudio projects You can ignore the part about RSA keys and SSH.

If you've never used Git before on the computer you are working on, configure git:

Open the a terminal on your computer and run the following 2 commands (you can paste them into the terminal):

git config --global user.name 'Full Name' 
git config --global user.email 'myid@uga.edu'

On a Mac, you can have Keychain remember your github password by running the following terminal command:

git config --global credential.helper osxkeychain

If you have not set up a Personal Access Token (PAT) on GitHub, create one:

The password that you use to login to GitHub’s website is NOT an acceptable credential when interacting with a repository via git/Rstudio (clone, push, pull, etc.). This was possible in the past, but now a PAT is required in place of a password for any git operations.

You have 2 options for creating a PAT.

  1. Go to https://github.com/settings/tokens and click “Generate token”.

  2. From R, do:

usethis::create_github_token()

create_github_token() will take you to the same Github token generation page.

PATs are like passwords, but are limited in scope. When creating a PAT on GitHub, you will be asked to select "scopes." Recommended scopes to select in GitHub are “repo”, “user”, and “workflow”. Recommended scopes will be pre-selected if you used create_github_token().

Click “Generate token”.

Copy the generated PAT to your clipboard. Or leave that browser window open and available for a little while, so you can come back to copy the PAT.

Provide this PAT in place of a password next time git or Rstudio for your GitHub password. Even though you are asked for a "password," you MUST provide the PAT in place of the password.

You may also store your PAT so R/Rstudio remembers it. In R, call gitcreds::gitcreds_set() to get a prompt where you can paste your PAT:

 > gitcreds::gitcreds_set()
 
 ? Enter password or token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 -> Adding new credentials...
 -> Removing credentials from cache...
 -> Done.

Set up an RStudio project for your Drake Lab Project and link it to the GitHub Repository

Navigate to the home page of your GitHub repository

Click the <>Code button, then HTTPS, and copy the URL (or copy the URL from the browser's address bar and add .git).
The URL should look something like: https://github.com/DrakeLab/surname-test.git Now, do one of the following:

  1. Open a terminal on your computer. In the terminal, change directories to the directory you want your project to be. (You'll be creating a brand new copy of your project there.)
cd path/to/directory
  • "Clone" the repository using the following command:
git clone "https://github.com/DrakeLab/surname-test.git"

Be sure to include the .git extension at the end of the URL. You should now have a copy of the repository as a folder on your computer.

  • In RStudio, File > New Project...
  • Choose Existing Directory
  • Browse to find the folder you just created, and click Create Project
  1. Clone the repository from within RStudio:
  • In RStudio File > New Project...
  • Choose Version Control
  • Choose Git
  • Paste the URL into the Repository URL box: https://github.com/DrakeLab/surname-test.git
  • You may change the project directory name and directory location or leave the defaults.
  • click Create Project

Get Working

Proceed to Project Management for tips on how to organize your Rstudio Project folder and how to work with Git.

Make some changes / additions

Add or modify files in your RStudio project.

First "commit"

  • In the Git tab, click the check boxes next to changed or new files you wish to add to the repository. Be sure to add the '.gitignore file the first time.
  • Click commit, enter a Commit message and press the Commit button.

Push

  • to sync your folder with the GitHub repository online, click Push.

Managing images and figures files in git

If exported figures are included in a git repository, the exported images should be tracked with git-lfs (Git Large File Storage). "Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise." Follow the instructions to install git-lfs, add lfs to your repository, and specify which file types or folders to track with lfs. Thereafter, lfs works invisibly and you simply commit and push changes as usual. Note: git-lfs is useful for tracking large data files as well as graphics.

Managing large datasets in Git

While git-LSF can also be used for large datasets, we recommend DVC for this purpose. Stay tuned for more info.

Lab Links

Clone this wiki locally