Git and Github

Jeremy Springman

University of Pennsylvania

Global Development: Intermediate Topics in Politics, Policy, and Data

PSCI 3200 - Spring 2025

Git and Github

Resources

Git Basics

Git is a version control program, so you can avoid…

analysis.R
analysis_v1.R
analysis_v2.R
...
analysis_FINAL_v2c.R

Data analysis projects

  • Contributions from multiple people
  • Many rounds or revisions
  • Require weeks/months
  • Vulnerable to devastating loss/failure

Git Basics

Version control can help

  • Detailed, permanent record of changes
  • Tracks changes and allows users to view or restore older versions
  • Helps avoid devastating loss/failure
  • Can be private or public

Git Basics

Each project is a repository (repo)

  • Data and code for projects are stored in a repo folder
  • Repo is hosted locally as a folder on your harddrive, and remotely on github.com
  • Make changes locally, record them as a commit, push them to the remote version
  • Share repo with collaborators; pull changes made by others from the remote version down to your local copy
  • Synching is not live (like Dropbox)

Git Basics

Usage

  • Edit files using your preferred software (RStudio, VSCode, MS Word, etc.)
  • When you’re done, record the changes as a commit, push them to the remote version

Collaboration

  • Precise record of who makes changes
  • Simultaneous editing can cause challenges

Git Basics

Essential commands

  • git pull origin main
  • git add .
  • git commit -m "describe your changes or vent frustration"
  • git push origin main

Git Basics


Git can be complicated

  • Often used for sophisticated software development
  • Branches, conflicts, merges, rebase
  • Massive online community to guide new users

Creating a Github account

Create an account for yourself or your organization

  • Go to github.com
  • Click “Sign-up” (top right)
  • Pick a username (ex. jrspringman)
  • Follow the instructions

Installing git

  1. Open the terminal/command prompt
  2. Check if you have git installed
git --version

Installing git

If no, install git

  • Mac should offer to install it for you
  • Windows visit gitforwindows.org, click “Download”, then double-click the .exe

Installing git

Installing git

Optional: Override the default branch name (select ‘main’)

Installing git

Make sure that “Git from the command line and 3rd-party software” is selected

Installing git

Installing git

Connect your GitHub account

  1. Open the terminal and enter the code below
  2. Replace "Your Name"and "yourname@email.edu" with your name/email used to sign up for GitHub
  3. Run the code
git config --global user.name "Your_user_name"
git config --global user.email "youremail@email.edu"

Connect your GitHub account

Connect your GitHub account

Check that the configuration worked

git config --list

Connect your GitHub account

Install a git client

  1. Visit desktop.github.com and click “Download”
  2. Double click the .exe

Install a git client

Create a new repo

Sign-in to your account on github.com and click “New”

Create a new repo

Give your repository a name and make it public or private

Create a new repo

Clone your repo

Open Github Desktop and “clone” the remote repo

Clone your repo

Clone your repo

Create a new repo

Commit changes

  • As you make changes to the repo, they will appear as “diffs” in the app
  • Add a description and make a “commit” to record those changes in git

Push to your repo

Push those changes to the remote version on Github.com

Push to your repo

Pull from your repo

When colleagues push a commit to the repo, you can pull their commit by clicking “Pull origin”

Pull from your repo

Github Pages

Create a website

Moving to RStudio

  • File \(\rightarrow\) New Project \(\rightarrow\) New Directory \(\rightarrow\) Quarto Website

Create a website

Create a website

Change output director to docs

Publish to Github pages

  • Keep a repository of your website
  • Push changes to your website via Github
  • See changes almost instantly

Publish to Github pages

  • Open repo on github.com
  • Settings \(\rightarrow\) Pages (left-sidebar)

Publish to Github pages

Publish to Github pages

Publish to Github pages

Publish to Github pages

Publish to Github pages

Publish to Github pages

Host Your Final Project

  • Delete _site folder (now its using docs)
  • Create data folder to store your dataset
  • Add final project .qmd file to your repo (or drop it into index.qmd)
  • Use _quarto.yml to add new pages to navigation bar
  • Render index.qmd; confirm that other pages have been rendered
  • Push commit and check that the website updated