2  Project Management with Git

Learning goals
By the end, you will be able to:

  • Configure Git on your computer and connect to GitHub securely.
  • Complete and submit an assignment via GitHub Classroom.
  • Use essential Git commands for day-to-day coursework.
  • Use common command-line operations to manage files and projects.
Prerequisites
  • You can use a terminal on your system. On Windows, I recommend Git Bash or WSL (Ubuntu).
  • You have a GitHub account.

2.1 Install and configure Git

2.1.1 Install Git

  • macOS: Install the Command Line Tools or use Homebrew.
# Option A: Trigger Apple CLT install when you first run git
xcode-select --install

# Option B: Homebrew (preferred if you use brew)
brew install git
  • Windows: Use Git for Windows (includes Git Bash) or enable WSL and install Git inside Ubuntu.
# WSL (Ubuntu) inside Windows
sudo apt update && sudo apt install -y git
  • Linux:
sudo apt update && sudo apt install -y git   # Debian/Ubuntu
# or
sudo dnf install -y git                       # Fedora

2.1.2 Identify yourself to Git

Set your name and email (must match the email used on GitHub for a clean history):

git config --global user.name "Your Name"
git config --global user.email "netid@uconn.edu"

Optional but recommended:

# Show colored output and a friendlier log
git config --global color.ui auto
git config --global init.defaultBranch main

# Better default editor (choose one you actually use)
# git config --global core.editor "code --wait"   # VS Code

2.1.3 Connect to GitHub: HTTPS vs SSH

  • HTTPS + Personal Access Token (PAT): simplest to start; you paste a token when Git asks for a password.
  • SSH keys: more convenient long-term (no token prompts). Recommended if you frequently push/pull.

2.1.3.1 Create and add an SSH key

# Generate a modern Ed25519 key
ssh-keygen -t ed25519 -C "netid@uconn.edu"
# Press Enter to accept default path; set a passphrase when prompted

# Start the agent and add your key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Print the public key and copy it
cat ~/.ssh/id_ed25519.pub

In GitHub: Settings → SSH and GPG keys → New SSH key → paste the public key.

Test the connection:

ssh -T git@github.com
# Expect: "Hi <username>! You've successfully authenticated..."

2.2 GitHub Classroom: homework workflow

Your instructor will share a GitHub Classroom invitation link. The link automatically creates a private repository for you.

2.2.1 Accept and clone the repository

  1. Open the invitation link and accept the assignment.
  2. After a minute, click into your created repo (e.g., dsda1010-hw01-<username>).
  3. Clone it once to your computer:
# Using SSH (recommended)
git clone git@github.com:course-org/dsda1010-hw01-<username>.git

# or using HTTPS (you will use a PAT when prompted)
# git clone https://github.com/course-org/dsda1010-hw01-<username>.git

Enter the folder, inspect starter files:

cd dsda1010-hw01-<username>
ls -la

Copy the homework template to this folder and start working on it. Make commits at appropriate stops.

Tip

Pro tip: If the repo includes a Quarto project, you can render it locally with quarto render before committing.

2.2.2 Make changes, commit, and push

# Check the current status
git status

# Stage a specific file, or use `.` to stage all changes
git add README.md

# Write a clear, imperative commit message
git commit -m "Complete Q1 and add explanation"

# Push your work to GitHub
git push origin main

Repeat the edit → add → commit → push loop as you progress. Your latest push before the deadline is your submission.

2.3 Core Git operations you will use often

2.3.1 Create or initialize a repository

# Start a new repo in an existing folder
git init

# Connect it to a new remote repository on GitHub
git remote add origin git@github.com:<user>/<repo>.git

# First commit and push
git add .
git commit -m "Initial commit"
git push -u origin main

2.3.2 Inspect history and changes

git status

# What changed since the last commit?
git diff

# What changed in staged files?
git diff --staged

# View history (pretty)
git log --oneline --graph --decorate --all

2.3.3 Branching

# Create and switch to a new branch
git switch -c feature/q2-solution

# List branches
git branch -vv

# Switch back
git switch main

2.3.4 Merging and fast-forwards

# On main, merge your feature branch
git switch main
git merge feature/q2-solution

# Delete the merged branch
git branch -d feature/q2-solution

2.3.5 Rebasing (optional, but good to know)

# Rebase your work on top of updated main
git fetch origin
git rebase origin/main

2.3.6 Fixing mistakes

# Unstage a file you just added
git restore --staged path/to/file

# Discard local changes in a file (careful: destructive)
git restore path/to/file

# Amend the last commit message (if not yet pushed)
git commit --amend -m "Better message"

# Revert a bad commit by creating a new inverse commit
git revert <commit-sha>

2.3.7 Handling merge conflicts (quick recipe)

# After a merge or rebase reports conflicts
git status            # see which files conflict

# Open conflicted files, look for <<<<<<<, =======, >>>>>>>
# Edit to the desired final content, then:
git add path/to/conflicted-file

git commit            # completes a merge
# or if rebasing:
git rebase --continue

2.3.8 .gitignore essentials

Create a .gitignore in the project root:

# Editors & OS
.DS_Store
.vscode/
.Rproj.user/

# Build outputs
*_cache/
*.html
*.pdf

# Dependencies
.Rhistory
.venv/
__pycache__/
.ipynb_checkpoints/

2.4 Command-line operations you should know

Use these across macOS, Linux, and WSL. On Windows Git Bash, equivalents mostly work too.

2.4.2 Files & folders

mkdir data figures scripts
mv oldname.txt newname.txt
cp src.txt backup/src.txt
rm -i unwanted.tmp      # -i asks before deleting

# Create a new file quickly
echo "Title" > README.md

# Edit with a CLI editor (choose one you like)
nano README.md
# or
vim README.md

2.4.3 Search & find

grep -n "pattern" file.txt        # search within a file
rg -n "pattern" .                  # ripgrep (if installed) across project
find . -name "*.qmd"              # find matching files

2.4.4 Environment & tooling

# Check versions
python --version
R --version
git --version
quarto --version

# (Optional) create a Python virtual environment
python -m venv .venv
source .venv/bin/activate     # Windows: .venv\Scripts\activate
pip install -r requirements.txt

2.5 End-to-end demo script (copy/paste)

# 0) Accept GitHub Classroom invite, then clone your repo
cd ~/courses/dsda1010
git clone git@github.com:course-org/dsda1010-hw01-<user>.git
cd dsda1010-hw01-<user>

# 1) Create a working branch
git switch -c work/q1

# 2) Edit files (use your editor), then stage & commit
echo "My answer to Q1" > answers/q1.md
git add answers/q1.md
git commit -m "Answer Q1"

# 3) Merge into main and push
git switch main
git merge work/q1
git push -u origin main

# 4) Pull in any upstream updates (if configured)
git fetch upstream
# Merge or rebase as instructed
git merge upstream/main

# 5) Verify on GitHub: files, commits, and CI checks (if any)

2.6 Troubleshooting FAQ

Git asks for a password on HTTPS and rejects it
Create a Personal Access Token on GitHub and use that instead of a password, or switch to SSH.

“Permission denied (publickey)” when using SSH
Your key is not added or not uploaded. Run ssh-add ~/.ssh/id_ed25519 then add the public key to GitHub Settings.

“fatal: not a git repository”
Run commands inside a folder that contains a .git directory, or run git init to create one.

Line endings (Windows vs Unix)
Set git config --global core.autocrlf input (macOS/Linux) or true (Windows) to avoid noisy diffs.

2.7 Quick reference (cheat sheet)

status   → what changed
add      → stage changes
commit   → record staged snapshot
push     → upload to remote
pull     → fetch + merge
fetch    → download without merging
switch   → move between branches
merge    → combine histories
rebase   → replay commits on a new base
log      → show history
restore  → discard or unstage changes
revert   → make an inverse commit
Important

Submission rule of thumb: If it is not pushed to GitHub by the deadline, it is not submitted.