A hands-on repository to learn GitHub's essential features: commits, branches, pull requests, and issues.
Associated blog post: Why I love Git and Github
Git helps you:
- Track changes without saving multiple file versions (
script_v1.R,script_v2_FINAL.R,script_v2_FINAL_ACTUALLY.R) - Experiment safely by creating test branches
- Collaborate effectively with clear history of who changed what and when
- Recover from mistakes by reverting to previous versions
GitHub adds:
- Cloud backup of your work
- Easy collaboration and code sharing
- Professional portfolio of your projects
Before you begin, you need:
- A GitHub account - Create one at github.com/join
- Git installed locally - Check if you have it by opening Terminal/Command Prompt and typing
git --version - Git configured with your identity - See Happy Git Chapter 7
For R users: I highly recommend the book Happy Git and GitHub for the useR by Jenny Bryan. Work through Chapters 1-8 to get set up properly.
For everyone else: GitHub's own getting started guide is excellent.
Open your terminal/command prompt and run:
git --version
git config --global user.name
git config --global user.emailIf these commands return values (not errors), you're ready to go!
Did you know you can edit files directly on GitHub's website? This is perfect for:
- Quick README updates
- Adding comments or documentation - we use issues
- Learning the basics before using Git locally
- Check out one of the issues for instructions
Try it now:
- Browse to any file in this repository (like practice_script.md)
- Click the pencil icon (✏️) to edit
- Make a small change
- Scroll down and write a commit message describing your change
- Click "Commit changes"
You just made your first commit! 🎉
What is a branch?
A branch is a parallel version of your repository. It lets you experiment without affecting the main code.
A helpful practice: When collaborating or experimenting, create a feature branch instead of working directly on main.
Why?
mainstays clean and working- You can experiment freely
- Multiple people can work on different features simultaneously and not overlap their changes
- Easy to discard failed experiments
Branch Workflow:
main branch (stable, working code)
│
├── your-name-feature (your experimental work)
│
└── another-feature (someone else's work)
Check out this issue and create a branch! Or follow GitHub hello-world guide which walks you through:
-
Creating a branch
- Click the branch dropdown (says "main")
- Type a new branch name:
yourname-practice - Click "Create branch"
-
Making changes
- Edit practice_script.md
- Add your name and a comment about what you're learning
- Commit your changes to your branch
-
Opening a Pull Request (PR)
- Click "Pull requests" tab -> "New pull request"
- Select your branch to merge into
main - Write a description of what you changed and why
- Click "Create pull request"
-
Review and Merge
- The repository owner reviews your changes
- If approved, your branch gets merged into
main - You can safely delete your branch after merging
Congratulations! You've completed the basic GitHub workflow. 🎉
Issues are GitHub's way to track tasks, bugs, and discussions.
Try it:
- Go to the Issues tab
- Find Issue
- Follow the instructions to practice commenting
# Create and switch to a new branch
git checkout -b experiment-analysis
# Make changes, commit them
git add modified_file.R
git commit -m "Testing new statistical method"
# If experiment works: merge it
git checkout main
git merge experiment-analysis
# If experiment fails: abandon it
git checkout main
git branch -D experiment-analysis # Delete the branch# You're working on a feature
git checkout -b feature-visualization
# Urgent bug appears! Switch to main
git checkout main
# Fix bug on a new branch
git checkout -b hotfix-data-import
# ... make fixes ...
git checkout main
git merge hotfix-data-import
# Return to your feature work
git checkout feature-visualization# You're on your feature branch
git checkout feature-analysis
# Update main branch
git checkout main
git pull origin main
# Bring main's updates into your branch
git checkout feature-analysis
git merge mainQ: What's the difference between Git and GitHub?
A: Git is the version control software that runs on your computer. GitHub is a website that hosts Git repositories and adds collaboration features.
Q: When should I commit?
A: Commit when you complete a logical unit of work. Each commit should represent one focused change with a clear message. Commit often!
Q: What makes a good commit message?
A:
- Start with a verb: "Add", "Fix", "Update", "Remove"
- Be specific: ❌ "Update code" -> ✅ "Add error handling to data import function"
- Keep it under 50 characters for the first line
- Just give up and write your feelings... hey, it happens. I have multiple terrible commit messages like 'random', 'changes', etc. Don't recommend, but it happens, we try to do better.
Q: I made a mistake in my last commit. Can I fix it?
A: Yes! If you haven't pushed yet:
# Fix the files, then:
git add fixed_file.R
git commit --amend --no-edit # Adds to previous commitQ: How do I see what changed?
git status # See which files changed
git diff # See line-by-line changes
git log --oneline # See commit historyGeneral best practices here
- Happy Git and GitHub for the useR - Chapters 1-8 for setup
- usethis package - R package to streamline Git/GitHub workflow
- GitHub Documentation
- GitHub Skills - Interactive tutorials
- Git Cheat Sheet
- Visualizing Git - See what Git commands do
- Learn Git Branching - Interactive branch tutorial
Open an issue and I'll help you out!
This repository is maintained by Javi Rudolph, Computational Literacy Librarian at UF Libraries, and is designed to support computational literacy in ecology and natural resource management.
For more resources on reproducible research in ecology, visit my website or check out my other repositories.