Skip to content

Integrate Git

If you use Positron or RStudio (or another IDE like VSCode), you can integrate Git directly into your workspace. The Hakai Data Mobilization team recommends using Positron as it offers excellent tools for working with data as well as git and GitHub. Check out Posit's guides on migrating to Positron.

Install git on your computer to integrate it with your terminal.

  1. Install Git on your computer (see Installation)
  2. Re-open Positron - it will recognize that git is now available
  3. Open an existing project or create a new one
  4. Click on the Version control icon in the left-hand vertical menu
  5. Click on the Initialize Repository button if present

If you see a 'Publish Branch' button instead, then git has already been setup for this project.

Connect Github (Recommended)

  1. Click on the GitHub icon in the left-hand vertical menu
  2. Click Sign in
  3. Complete the sign-in steps to authenticate

Integrate Git into RStudio

  1. Install Git, then restart RStudio
  2. Go to Tools > Version Control > Project Setup
  3. Select Git and restart RStudio when prompted
  4. Go to Tools > Terminal > Terminal Options
  5. Set New terminals open with to Git Bash

Verify Your Configuration

  1. Open a new terminal: Tools > Terminal > New Terminal
  2. Run git --version — you should see the version number
  3. Run echo $SHELL — you should see /usr/bin/bash
  4. Open the RStudio Console, and run install.packages("usethis")
  5. Run usethis::git_vaccinate() (Optional/recommended)
  6. Run usethis::create_github_token() and login to github to complete
  7. Store this Personal Access Token (PAT) in your password manager
  8. Run gitcreds::gitcreds_set()
  9. Finally, to see your git settings, run usethis::git_sitrep()
  10. This output is also helpful when troubleshooting Git

Example output from usethis::git_sitrep()

── Git global (user) Name: "Your Name" Email: "youremail@example.com" Global (user-level) gitignore file: ~/.gitignore
• Vaccinated: TRUE
• Default Git protocol: "https" Default initial branch name: "main"

── GitHub user
• Default GitHub host: "https://github.com" Personal access token for "https://github.com": <discovered>
• GitHub user: "yourusername" Token scopes: "admin:public_key", "gist", "read:org", "read:project", "workflow", and "repo"

── Active usethis project: "[the filepath to your current git project]" ──

── Git local (project) Name: "Your Name" Email: "youremail@example.com" Default branch: "main" Current local branch  remote tracking branch:
  "feature/new-feature"  <unset>

── GitHub project
ℹ Project does not use GitHub.

With this setup complete, you are ready to create a new git repository.

Resources