Skip to content

Latest commit

 

History

History
444 lines (316 loc) · 10.6 KB

slides.md

File metadata and controls

444 lines (316 loc) · 10.6 KB
theme favicon layout coverBackground sectionBackground themeConfig
./
./assets/favicon.ico
cover
./assets/cover.png
./assets/section.png
logo author avatar showProgressBar
./assets/logo.png
Steven Hill
./assets/avatar.png
true

Git for Beginners

Fearless coding and reproducible research


transition: fade-out

Table of Content


layout: section transition: fade-outs

Why Git / GitHub?


layout: image-right image: "./assets/scratch_comic_small.png" backgroundSize: contain imageSize: 100% transition: fade-out

The Problem

Challenges Faced Without Version Control

  • "Where is this script we used in the last project?"
  • "Which version of the script is the right one?"
  • "I accidentally overwrote a file."
  • "Where's the latest data?"
  • "Who changed what, and why?"

transition: fade-out

Why use Git/Github?

Reproducibility, teamwork, and fearless coding

  1. 🔁 Track Changes: See what changed and when.
  2. 🧑‍🤝‍🧑 Collaborate: Work with others seamlessly.
  3. 💾 Backup: Save your work automatically (with GitHub)
  4. 🔬 Reproducibility: Ensure your research can be repeated.
  5. 📢 Share: Publish your work with the world.

layout: section transition: fade-out

What is Git and Github?


layout: two-cols transition: fade-out

::left::

What is Git?

A Distributed Version Control System

Git is a free and open-source tool designed to help developers:

  • Track changes in their files over time.
  • Collaborate with others on the same project.
  • Experiment with new ideas without fear of losing progress.

::right::

gitGraph TB:
    commit id: "version 0.0"
    commit id: "version 0.1"
    checkout main
    branch Steven
    commit id: "new feature"
    commit id: "documentation"
     branch Jane
    checkout Steven
    commit id: "fix code"
    checkout main
    merge Steven
    commit id: "version 0.2"
    checkout Jane
    commit id: "fix documentation"
    checkout main
    merge Jane id: "version 0.4.2"
Loading

transition: fade-out

What is Git?

A Distributed Version Control System

Key Features of Git

  1. Version History: Keep a detailed history of every change made to your files.
  2. Branching: Create separate branches to work on new features or fixes.
  3. Merging: Combine changes from different branches seamlessly.
  4. Distributed: Work offline—Git stores the entire repository locally.
  5. Speed: Perform operations like commits and branching quickly.

transition: fade-out

Github

A Platform for Collaboration and Hosting

GitHub is a web-based platform built on top of Git. It provides tools for:

  • Hosting repositories: Store your code and project files in the cloud.
  • Collaboration: Work with others through pull requests, issues, and discussions.
  • Version control: Track changes and manage your project history.
  • Automation: Use GitHub Actions for CI/CD workflows.
  • Publishing: Host websites and documentation with GitHub Pages.

transition: fade-out

Git vs GitHub

Version control tool vs platform for collaboration


transition: fade-out

Application in Ecology

Practical ways GitHub powers open ecological research


layout: section transition: fade-out

Git Basics


transition: fade-out

Basic Concept

flowchart TD
    style WD fill:#E3F2FD,stroke:#2196F3,stroke-width:2px
    style STG fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px
    style LOCAL fill:#C8E6C9,stroke:#388E3C,stroke-width:2px
    style REMOTE fill:#FFCDD2,stroke:#D32F2F,stroke-width:2px

    WD["📂 Working Directory"]
    STG["🗃️ Staging Area"]
    LOCAL["📦 Local Repository"]
    REMOTE["🌐 Remote Repository"]

    WD -->|git add| STG
    STG -->|git commit| LOCAL
    LOCAL -->|git push| REMOTE
    REMOTE -->|git fetch / git pull| LOCAL
    LOCAL -->|git checkout| WD

Loading

transition: fade-out

Git Initialization

Set up your Git environment

# Step 1: Set your user info (only once)
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

# Step 2: Initialize a new repository
git init my_first_project
cd my_first_project

transition: fade-out

Git Add & Commit

Track and save your work

# Step 3: Create a file
echo "Hello Git" > README.md

# Step 4: Track the file
git add README.md

# Step 5: Save a snapshot
git commit -m "Initial commit"

Always write meaningful commit messages to describe what you’ve changed and why.


transition: fade-out

Branching & Merging

Parallel development made easy.

# Create and switch to a new branch
git checkout -b feature-idea

# Work on your changes, then:
git add .
git commit -m "Add awesome feature"

# Merge your branch into main
git checkout main
git merge feature-idea

Use git branch -d [branch] to delete branches you no longer need and keep your repo clean.


transition: fade-out

Git Stash

Save changes without committing.

git stash             # Temporarily saves uncommitted changes
git stash list        # See all stashed changes
git stash apply       # Apply the most recent stash
git stash pop         # Apply & remove the stash
git stash drop        # Delete a stash

Git Stash helps you pause work, switch tasks, and keep your workspace clean without committing changes.


transition: fade

Git Rebase

Rewrite your commit history

# Rebase your branch onto main
git checkout feature-branch
git rebase main

# Resolve conflicts if needed, then:
git add <file>
git rebase --continue

transition: fade

Git Restore & Reset

Don’t panic — how to fix Git mistakes.

git restore --staged <file>   # Undo git add
git reset --soft HEAD~1       # Undo last commit (keep changes)
git reset --hard HEAD~1       # Undo last commit (discard changes)
git checkout HEAD -- <file>   # Restore deleted file

Use git diff before resetting to see what changes you’re about to discard


transition: fade

git log

View the commit history of a repository

git log --oneline --graph  ## add `--oneline` or `--graph` for visual clarity 
git blame my_script.py.    ## see who edited each line of a file

transition: fade-out

Push to GitHub

Connect your local repo to the cloud

Step 1: Create a GitHub Account

  • If you don’t already have a GitHub account, sign up here.
  • Once signed in, create your repository.

Step 2: Connect your local repo to the cloud

git remote add origin https://github.com/yourusername/your-repo.git # Add the remote (replace with your repo URL)
git branch -M main             # Set the default branch
git push -u origin main        # Push your commits

layout: two-cols transition: fade-out

::left::

GitHub Etiquette

Collaborate with kindness and clarity

  • Write clear commit messages (what + why)
  • Don’t commit broken code to main
  • Use .gitignore to keep clutter out
  • Clean up unused branches regularly
  • Be kind and constructive in Pull Request comments
  • Always write a description when opening a PR

::right::


transition: fade-out

GitHub Desktop & GUI Tools

Prefer clicking to typing? No worries!


layout: center transition: fade-out

🎉 You’re Ready to Git Going!

“The best way to learn Git is to use it regularly"

✅ Don’t be afraid to break things
✅ Ask questions, open issues
✅ Collaborate early and often


layout: section transition: fade-out