Git & GitHub Setup
Version control configuration
Version control is essential for all lab work. This guide covers installing and configuring Git and GitHub.
Install Git
| Platform | Method |
|---|---|
| Longleaf | module load git (already available) |
| macOS | xcode-select --install or brew install git |
| Linux | sudo apt install git |
| Windows | Git for Windows (includes Git Bash) |
Configure Git
These settings identify your commits:
git config --global user.name "Your Name"
git config --global user.email "your.email@unc.edu"
# Recommended settings
git config --global init.defaultBranch main
git config --global pull.rebase falseExplanation:
user.nameanduser.email: Attached to every commit you makeinit.defaultBranch main: New repos usemaininstead ofmasterpull.rebase false: Use merge commits when pulling (simpler for beginners)
GitHub CLI (Optional but Recommended)
The GitHub CLI (gh) makes it easier to work with GitHub from the command line.
| Platform | Method |
|---|---|
| Longleaf | May need to install manually or use web interface |
| macOS | brew install gh |
| Linux | See GitHub CLI install |
| Windows | winget install GitHub.cli or download from cli.github.com |
# Authenticate
gh auth loginFollow the prompts to log in via browser or token.
Useful gh commands:
gh repo clone rashidlab/project-name # Clone a repo
gh pr create # Create a pull request
gh pr list # List open PRs
gh issue create # Create an issue
gh issue list # List open issuesSSH Keys for GitHub
SSH keys let you push/pull without entering your password each time.
Generate a Key
# Generate key (if you don't have one)
ssh-keygen -t ed25519 -C "your.email@unc.edu"Press Enter to accept the default file location. You can add a passphrase for extra security.
Add Key to SSH Agent
# Start ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519Add Key to GitHub
# Copy public key
cat ~/.ssh/id_ed25519.pubThen add to GitHub:
- Go to GitHub –> Settings
- Click SSH and GPG keys
- Click New SSH key
- Paste your public key
- Give it a descriptive title (e.g., “Longleaf” or “MacBook”)
Test the Connection
ssh -T git@github.com
# Should say: "Hi username! You've successfully authenticated..."Git on Longleaf with OnDemand
If using OnDemand + RStudio for development:
Initial Setup (One Time)
- Launch RStudio Server via OnDemand
- Open Terminal tab in RStudio
- Configure Git (see above)
- Set up GitHub authentication:
Option A: HTTPS with credential caching
git config --global credential.helper 'cache --timeout=28800'
git clone https://github.com/rashidlab/your-repo.gitYou’ll enter your username and personal access token once, and it caches for 8 hours.
Option B: SSH keys (more permanent)
ssh-keygen -t ed25519 -C "your_onyen@unc.edu"
cat ~/.ssh/id_ed25519.pub
# Copy this key to GitHub: Settings --> SSH Keys --> New SSH KeyDaily Workflow
Launch RStudio via OnDemand
Open your project (File –> Open Project)
Pull latest:
git pull origin mainWork on code
Commit and push:
git add -A git commit -m "feat: add new analysis function" git push origin main
RStudio Git Integration
RStudio has built-in Git support:
- Git tab in top-right pane shows changed files
- Diff button shows changes
- Commit button opens commit dialog
- Pull/Push buttons sync with remote
To enable: Tools –> Project Options –> Git/SVN –> Select Git
Verification Checklist
After setup, verify Git and GitHub work correctly:
On Longleaf
ssh your_onyen@longleaf.unc.edu
module load git
git --version
git config --list | grep user
ssh -T git@github.comLocally
git --version
git config --list | grep user
ssh -T git@github.com
gh --version
gh auth statusTest a Clone
# Test SSH access
git clone git@github.com:rashidlab/lab-handbook.git test-clone
rm -rf test-cloneCommon Issues
| Issue | Solution |
|---|---|
| Permission denied (publickey) | SSH key not set up; see SSH Keys for GitHub |
| Authentication failed | Use SSH instead of HTTPS, or use a personal access token |
| Git not found | Load module on Longleaf (module load git) or install locally |
For more detailed troubleshooting, see Troubleshooting.
Next Steps
- GitHub Fundamentals - Issues, PRs, Discussions
- Git Practices - Workflow and conventions
- First Project - Start your first lab project
Next: GitHub Fundamentals | First Project