Setup
git config --global user.name "Name" |
Set your name for commits |
git config --global user.email "email" |
Set your email for commits |
git init |
Create a new repository in the current folder |
git clone <url> |
Download a remote repository to your computer |
Daily Workflow
git status |
Show which files are modified, staged, or untracked |
git add <file> |
Stage a file for the next commit |
git add . |
Stage all changed files |
git commit -m "message" |
Save a snapshot with a descriptive message |
git diff |
Show unstaged changes |
git diff --staged |
Show staged changes (what will be committed) |
git log --oneline |
View commit history (compact) |
git log |
View commit history (detailed) |
Undoing Things
git restore --staged <file> |
Unstage a file (keep edits) |
git restore <file> |
Discard edits, revert to last commit (destructive) |
git reset --soft HEAD~1 |
Undo last commit (keep files staged) |
Remotes (GitHub)
git remote add origin <url> |
Link local repo to GitHub |
git push -u origin main |
Push commits to GitHub (first time) |
git push |
Push commits (after -u is set) |
git pull origin main |
Download new commits from GitHub |
Branches
git branch <name> |
Create a new branch |
git checkout <branch> |
Switch to a branch |
git checkout -b <name> |
Create and switch in one step |
git merge <branch> |
Merge a branch into the current branch |
git branch -d <name> |
Delete a branch (after merging) |
SSH Setup (One-Time)
# Generate key
ssh-keygen -t ed25519 -C "you@email.com"
# Start agent and add key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Copy public key (paste into GitHub Settings > SSH Keys)
cat ~/.ssh/id_ed25519.pub
# Test connection
ssh -T git@github.com
.gitignore Template for R Projects
# Data files
*.csv
*.dta
*.rds
*.xlsx
data/
# R artifacts
.Rhistory
.RData
.Rproj.user/
# Output (can be regenerated)
*.pdf
*.html
output/
# System files
.DS_Store
Thumbs.db