Git & GitHub Tutorial

Learn how to contribute to SWECC Labs projects step by step

Prerequisites

Install Git

First, you'll need to install Git on your computer:

  • Windows: Download from git-scm.com
  • Mac: it's probably already installed
  • Linux: you probably know what to do

Create a GitHub Account

If you haven't already, create a free account at GitHub.com

GitHub signup page

Forking the Repository

Fork the Repository

Navigate to the SWECC Labs repository you want to contribute to and click the "Fork" button in the top right. For example, for your first contribution, you should fork the swecc-labs repository.

GitHub fork button location
Tip: A fork creates your own copy of the repository where you can make changes safely.

Cloning Your Fork

Clone the Repository

Copy your fork's URL and clone it to your local machine:

GitHub clone button and URL
git clone https://github.com/your-username/repository-name.git

Add Upstream Remote

Link your fork to the original repository:

git remote add upstream https://github.com/swecc-uw/repository-name.git

Making Changes

Create a Branch

Create a new branch for your changes:

git checkout -b branch-name

Commit Your Changes

After making your changes, commit them:

git add .
git commit -m "Description of your changes"
git push origin branch-name
Tip: Write clear, descriptive commit messages that explain what your changes do.

Creating a Pull Request

Open a Pull Request

Go to your fork on GitHub and click "Pull Request"

GitHub PR creation page
Tip: Keep your PR focused on a single change. This makes it easier to review and more likely to be merged quickly.

Git CLI Reference

Common Git Workflows

I want to... Commands to use
Start working on a new feature git fetch upstream
git checkout upstream/main
git checkout -b feature-name
Save my work in progress git add .
git commit -m "WIP: description of changes"
Update my fork with latest changes git fetch upstream
git checkout main
git merge upstream/main
git push origin main
Undo my last commit (but keep changes) git reset HEAD~1
Discard all my uncommitted changes git reset --hard HEAD
Switch to a different branch without losing changes git stash
git checkout other-branch
git stash pop # to get changes back
Fix conflicts with main branch git fetch upstream
git merge upstream/main
# Fix conflicts in editor
git add .
git commit -m "Merge main and resolve conflicts"
See what changes I've made git status # files changed
git diff # actual changes
Push changes for PR git push origin branch-name
# Then create PR on GitHub
Tip: These commands are for common workflows you'll encounter. If you need to do something not listed here, try searching the operation on GitHub's Git documentation.

Help Improve This Guide

Contribute to Documentation

This guide is open source and we welcome improvements! If you find something unclear, spot a mistake, or have ideas for better explanations, please contribute. You can:

  • Add missing information
  • Clarify confusing sections
  • Fix typos or errors
  • Improve the layout or design
  • Add more helpful tips

Just fork the repository, make your changes, and submit a pull request. It's a great way to make your first contribution!

Back to Home