💻

Git and GitHub Basics

Jul 14, 2025

Overview

This lecture offers a clear, beginner-friendly explanation of Git and GitHub, covering essential commands and workflows for saving code and collaborating with others.

Understanding Git

  • Git is a software tool for tracking and saving changes in code projects.
  • MacOS and Linux come with Git pre-installed; Windows users must download Git Bash.
  • Knowing Git is essential for all programmers, similar to understanding the command line.
  • Git acts as a "memory card" for code, allowing you to save progress and recover previous versions if files are lost.

Basic Git Workflow

  • Start tracking a folder by running git init in your project directory.
  • Use git add . to stage all changes for saving, or specify a file to stage only that file.
  • Commit staged changes to history with git commit -m "Your message".
  • View your commit history using git log (shows messages, dates, and commit hashes).
  • Restore a previous state with git checkout <commit-hash>.

Introduction to GitHub

  • GitHub is an online platform for storing code repositories and collaborating with others.
  • Create a GitHub profile and a new repository (repo) to host your project online.
  • Connect your local project folder to GitHub using git remote add origin <repository-url>.
  • Upload changes using git push origin master (or your branch name).
  • Others can view, download, and contribute to your code through GitHub.

Branches and Collaboration

  • By default, all code is on the master branch; branches allow parallel development.
  • Create a new branch with git checkout -b <branch-name>.
  • Changes on other branches don't affect master until they're merged.
  • Merge another branch into master to combine changes.
  • On GitHub, collaborators propose changes via pull requests, which can be reviewed and merged by the repository owner.
  • Always sync local and remote repositories: use git push to upload and git pull to download changes.

Key Terms & Definitions

  • Git — Local version control tool for tracking code changes.
  • GitHub — Cloud-based platform for code sharing and collaboration.
  • Repository (repo) — Folder or project tracked by Git/GitHub.
  • Commit — Saved snapshot of project changes with a message.
  • Branch — Parallel version of the code for separate development.
  • Remote — Online version of your local git repository (e.g., on GitHub).
  • Pull Request — Request to merge changes from one branch or contributor into another.

Action Items / Next Steps

  • Install Git (Git Bash for Windows) if not already installed.
  • Practice basic Git commands: init, add, commit, log, checkout.
  • Create a GitHub account and a test repository.
  • Connect your local project to GitHub and practice pushing and pulling changes.