Friday, October 17, 2025

Getting Started with GitHub: A Beginner's Guide

 Getting Started with GitHub: A Beginner's Guide

GitHub is a web-based platform for version control and collaboration, built around Git (a distributed version control system). It allows you to store code, track changes, collaborate with others, and host projects. Whether you're a solo developer or working in a team, GitHub streamlines workflows. Below, I'll walk you through the essentials step by step. This assumes you're new to it—feel free to ask for deeper dives on specific parts!1. Set Up Your Environment
  • Create a GitHub Account:
    • Go to github.com and sign up for free (email, username, password). Verify your email.
    • Choose a plan: Free for public repos; paid for private ones with more features.
  • Install Git (the command-line tool GitHub uses):
    • Download from git-scm.com for your OS (Windows, macOS, Linux).
    • During installation, accept defaults or customize (e.g., use VS Code as editor).
    • Verify: Open a terminal/command prompt and run git --version. It should show something like git version 2.XX.X.
  • Configure Git Locally (one-time setup):
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    Use the email tied to your GitHub account.
2. Create Your First Repository (Repo)
  • On GitHub's website:
    1. Click the "+" icon (top right) > "New repository".
    2. Name it (e.g., "my-first-project"), add a description.
    3. Choose public/private, initialize with a README (recommended—it's your project's intro file).
    4. Click "Create repository".
  • You'll get a URL like https://github.com/yourusername/my-first-project.git. Copy it—you'll need it later.
3. Work Locally: Clone, Edit, and Push ChangesGitHub shines when you work offline and sync changes. Use a terminal for these commands.
  • Clone a Repo (download it to your computer):
    git clone https://github.com/yourusername/my-first-project.git
    cd my-first-project  # Enter the folder
    This creates a local copy.
  • Make Changes:
    1. Create/edit files (e.g., open README.md in a text editor like VS Code and add content).
    2. Stage changes: git add . (stages all files) or git add filename.txt (specific file).
    3. Commit (save snapshot): git commit -m "Add initial project description".
    4. Push to GitHub: git push origin main (uploads changes; main is the default branch).
  • Pull Updates (from others or your remote changes):
    git pull origin main
    This fetches and merges remote changes.
4. Key GitHub WorkflowsUse these for collaboration or organizing work:
Workflow
When to Use
Basic Steps
Branching
Experiment without breaking main code.
git checkout -b new-feature (create/switch branch) git push origin new-feature On GitHub: Switch branches via dropdown.
Pull Requests (PRs)
Propose changes for review (great for teams).
Push branch, go to repo > "Pull requests" > "New pull request". Add title/description, assign reviewers, merge when approved.
Forking
Contribute to someone else's repo.
Click "Fork" on their repo page. Clone your fork, make changes, submit PR to original.
Issues
Track bugs, tasks, or ideas.
Repo > "Issues" > "New issue". Assign labels, milestones, or assignees.
  • Pro Tip: Always work on branches (git checkout -b), not directly on main. Merge via PRs for safety.
5. Collaboration and Features
  • Invite Collaborators: Repo settings > "Collaborators" > Add GitHub usernames.
  • GitHub Actions: Automate workflows (e.g., CI/CD). Start with a .github/workflows folder and YAML files—docs at github.com/actions.
  • GitHub Pages: Host static sites for free. Enable in repo settings > "Pages" > Source: Deploy from branch.
  • Markdown Magic: Use .md files for formatted docs (e.g., README.md). Syntax: # Heading, *italic*, **bold**, [link](url).
6. Common Commands Cheat SheetHere's a quick reference table for terminal basics:
Command
Purpose
Example
git status
Check staged/unstaged changes.
git status
git log
View commit history.
git log --oneline (short version)
git diff
See changes before staging.
git diff
git remote -v
List connected remotes.
git remote add origin <url> (if needed)
git reset --hard HEAD
Undo uncommitted changes (careful!).
git reset --hard HEAD
Tips and Best Practices
  • Learn Git First: GitHub is Git-powered. Practice with git-scm.com/book (free e-book).
  • GUI Tools: If CLI feels overwhelming, try GitHub Desktop (desktop app) or VS Code's built-in Git support.
  • Security: Use SSH keys for authentication (generate via ssh-keygen, add to GitHub settings > SSH keys). Avoid committing secrets—use .gitignore files.
  • Troubleshooting: Stuck? Search GitHub's help docs or Stack Overflow. Common error: "Not a git repository"? Run git init first.
  • Next Steps: Explore GitHub's free courses for interactive tutorials.
This covers 80% of daily GitHub use

Lecture Notes: Optimising Numerical Code

Lecture Notes: Optimising Numerical Code Prerequisites: Basic Python programming Understanding of NumPy arrays and vector ...