Learn GitHub
$ gh ghfoundations.ghintro

Introduction to Git and GitHub

6 learning objectives · 11 key terms · 6 commands · 3 diagrams · 5 quiz questions

$objectives

Introduction to Git and GitHub

Foundations

Module 1 of 5 · lesson 1 in this module

What you'll be able to do

  • Explain what version control is and the problem it solves
  • Describe what Git is, what GitHub is, and how they differ
  • Compare centralized and distributed version control
  • Install Git and prove the install worked
  • Create a GitHub account and configure your Git identity
  • Name the four places a change lives: working directory, staging area, local repository, remote repository
$concept

The idea, in plain language

Version control is a project's memory. Every time you reach a state worth keeping, you record a snapshot with a message explaining why. From that point on you can see who changed what and when, compare any two snapshots, undo a bad change without losing the good work around it, and let several people edit the same project at once without emailing zip files around. Without version control, "the final version (2) REAL final.zip" is the whole strategy — and one overwritten file can cost a week.

Git is a distributed version control system. It was written in 2005 by Linus Torvalds to manage the Linux kernel, after the tool the kernel team had been using stopped being free to use. The key word is distributed: the entire history of a project is copied to your machine when you clone it, so you can commit, branch, compare and inspect history while completely offline. Git needs no server to work — a laptop with one repository is a complete, fully functional setup.

GitHub is a website that hosts Git repositories and adds collaboration on top. It gives your repository a permanent home with a web address, and layers on the things teams need: pull requests for reviewing work before it lands, issues for tracking tasks, Actions for running automated tests, permissions, releases and more. The short version: Git is the tool that records history, GitHub is the place where teams share that history. You can use Git without GitHub, and you can never use GitHub without Git underneath it.

$key terms

Key terms

Version control
A system that records snapshots of a project over time so any earlier state can be inspected or restored.
Repository (repo)
A project tracked by Git — a folder plus the hidden .git directory that holds its entire history.
Commit
One saved snapshot, with an author, timestamp and message. The unit of history in Git.
Git
The distributed version control program that runs on your machine.
GitHub
A cloud platform that hosts Git repositories and adds collaboration features such as pull requests and issues.
Remote
A named copy of the repository on another machine — usually a GitHub repository — that you push to and pull from.
Working directory
The files you are actually editing right now, as they appear in your editor.
Staging area
The holding list of changes you have chosen to include in the next commit.
Local repository
The committed history stored inside the hidden .git folder on your own machine.
Distributed version control
Every clone is a complete repository with full history, not a thin client talking to one central server.
HEAD
A pointer to the commit you currently have checked out — "where you are" in history.
$steps

How it works, step by step

  1. 1
    Check whether Git is already installed

    Many systems ship with Git, especially macOS and Linux. Ask for its version before installing anything — if you get a version number back, you are done.

    check firstbash
    git --version
  2. 2
    Install Git with your platform package manager

    Prefer the official package manager over downloading an installer file: it keeps Git updatable and puts the commands on your PATH automatically.

    installbash
    # macOS (Homebrew)
    brew install git
    
    # Windows (winget, in PowerShell)
    winget install --id Git.Git -e
    
    # Ubuntu / Debian
    sudo apt install git
  3. 3
    Verify the install

    A version number in reply means the git program is on your PATH and ready to use. No output, or "command not found", means the install or the PATH did not take effect — restart the terminal first.

    verifybash
    git --version
  4. 4
    Create your GitHub account

    Sign up at github.com with a username you are happy to appear on public contributions, then turn on two-factor authentication straight away. The email you use here is the one your commits should be attributed to.

  5. 5
    Tell Git who you are

    Git stamps every commit with a name and email. Until you set these, commits can carry a machine-generated placeholder that GitHub cannot match to your account — so the work does not appear on your profile.

    identitybash
    git config --global user.name "Ada Lovelace"
    git config --global user.email "ada@example.com"
  6. 6
    Choose how you will drive it

    The terminal gives you the full command set and matches every tutorial you will read. A GUI (GitHub Desktop, GitKraken, VS Code's Source Control panel) is a friendly viewer for the same history. Learn the terminal first and the GUI becomes optional; learn only the GUI and you will be stuck the first time a rebase goes sideways.

$commands

Commands worth memorising

Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.

versionbash
git --version
Output
git version 2.46.0

Confirms Git is installed and tells you which version you have.

set your namebash
git config --global user.name "Ada Lovelace"

Stored once in your global config and used for every commit on this machine.

set your emailbash
git config --global user.email "ada@example.com"

Use an email verified on your GitHub account, otherwise commits will not link to your profile.

default branch namebash
git config --global init.defaultBranch main

Makes every new repository start on main instead of the old default master — matches GitHub.

line-ending sanity (Windows)bash
git config --global core.autocrlf true

Converts line endings on checkout and commit so Windows and Linux collaborators stop trading CRLF noise.

inspect your configbash
git config --list
Output
user.name=Ada Lovelace
user.email=ada@example.com
init.defaultbranch=main

Shows every setting Git will use, merging system, global and repository config.

$diagrams

Workflow diagrams

Diagram 1Your code lives in three places, not one

The same project exists locally and, once you push, on GitHub. The local copy is always the complete repository — GitHub is a shared copy, not the original.

Reading the diagram
  1. You edit files in the working directory.
  2. git commit records a snapshot into the local repository — no internet needed.
  3. git push copies those commits up to the GitHub remote so others can pull them.
Diagram 2The four areas and the commands that move work between them

Learn this picture once and most Git confusion disappears: every command you will ever run moves work along one of these arrows.

Reading the diagram
  1. git add moves selected changes from the working directory into the staging area.
  2. git commit turns everything staged into one snapshot in your local repository.
  3. git push publishes local commits to the GitHub remote.
  4. git fetch downloads new remote commits without touching your files; git pull does a fetch and then merges or rebases them into your branch.
Diagram 3Git versus GitHub, side by side

They are not two names for one thing, and neither replaces the other.

Reading the diagram
  1. Git is the tool; GitHub is the place you share the tool’s output.
  2. Every pull request, issue and Actions run on GitHub ultimately operates on commits that Git created.
$example

Worked example

A brand-new project on your first day. Nothing here touches GitHub yet — that is the point: Git is already fully useful by itself.

first-day sessionbash
mkdir recipe-book && cd recipe-book
git init
# Initialized empty Git repository in /home/ada/recipe-book/.git/

printf '# Recipe Book\n\nA tiny project for learning Git.\n' > README.md
git status
# On branch main
# No commits yet
# Untracked files:  README.md

git add README.md
git commit -m "Add project README"
# [main (root-commit) 4f1c2ab] Add project README
#  1 file changed, 3 insertions(+)

git log --oneline
# 4f1c2ab (HEAD -> main) Add project README
Output
git log shows one commit, and HEAD -> main tells you where you are. GitHub has no idea this project exists.
1mkdir and cd create the project folder and move into it. Git has not been involved yet.
2git init creates the hidden .git directory, which turns an ordinary folder into a repository. It prints the branch name it created (here main because we set init.defaultBranch).
3git status is the command you will run most often. It reports "No commits yet" and lists README.md as untracked — Git can see the file but is not tracking its history.
4git add README.md stages the file: it is now on the list for the next snapshot.
5git commit writes the snapshot with the message "Add project README" and prints a short hash plus a summary of what changed.
6git log --oneline shows the history: one commit, its short hash, and HEAD -> main planted on it. Everything above happened offline.
$use cases

Where you'll use it

▸Solo projects: an undo history you can actually navigate, with messages explaining each decision.
▸Team projects: several people editing the same codebase without overwriting each other.
▸Open source: strangers contribute patches through pull requests instead of email threads.
▸Debugging: find the exact commit that introduced a bug, then read the message that explains it.
▸Automation: GitHub Actions runs your tests on every push, catching mistakes before review.
▸Backups and portfolios: a GitHub profile that shows real work, with contribution history.
$mistakes

Common mistakes

  • Saying "GitHub" when you mean Git (or the reverse) — it makes every later conversation confusing.
  • Installing Git but never setting user.name and user.email, so commits are attributed to a machine name GitHub cannot match.
  • Setting user.email to a work address that is not verified on the GitHub account, so contributions never show on the profile.
  • Assuming you need an internet connection to commit. Git is local; only push and pull need the network.
  • Downloading a random installer instead of using your package manager, then fighting a stale Git for months.
  • Skipping two-factor authentication on a new GitHub account — account takeovers start here.
$best practices

Best practices

  • Configure Git identity, default branch and line endings immediately after installing, before the first commit.
  • Learn the terminal commands first; add a GUI afterwards if you want one.
  • Keep Git up to date with your package manager so you get modern defaults and fixes.
  • Pick a GitHub username you will still like in five years — it appears on every contribution.
  • Turn on two-factor authentication as soon as the account exists.
$exercise

Hands-on exercise

Stand up a working Git + GitHub environment

Prove the whole toolchain works before you learn any real Git commands.

  1. Run git --version. If there is no version number, install Git with your package manager and try again.
  2. Set your name and email: git config --global user.name "Your Name" and git config --global user.email "you@example.com".
  3. Run git config --list and confirm both values appear, spelled exactly as you typed them.
  4. Create a free GitHub account, verify the email, and enable two-factor authentication.
  5. Create an empty folder, run git init inside it, and note which branch name Git reports.
  6. Write down, in one sentence each, what Git is and what GitHub is — then check your sentences against the Git versus GitHub table in this lesson.

💡 Hint: If git --version fails after installing on Windows, close and reopen the terminal — PATH changes only apply to new sessions.

Done when: git config --list prints your name and email, and you have a GitHub account with 2FA enabled.

$quiz

Checkpoint quiz

0 of 5 answered · 0 correct

  1. Multiple choiceQ1

    Which statement best describes the relationship between Git and GitHub?

  2. Command outputQ2

    What does this command print on a machine with Git installed?

    git --version
  3. True or falseQ3

    True or false: you need an internet connection to create a commit.

  4. TroubleshootingQ4

    You committed work, pushed it, and opened a pull request — but none of the commits show up on your GitHub profile. What is the most likely cause?

  5. Multiple choiceQ5

    Which area holds changes you have selected for the next commit?

$summary

Module summary

  • Version control gives a project a navigable history instead of a pile of copies.
  • Git is a distributed version control tool that works fully offline; every clone holds the complete history.
  • GitHub hosts Git repositories and adds collaboration: pull requests, issues, Actions, releases and permissions.
  • Four areas hold your work: working directory, staging area, local repository and remote repository.
  • git add, git commit and git push move work rightwards through those areas; git fetch and git pull bring it back.
  • Configure user.name and user.email before your first commit so GitHub can attribute your work.

Next up: Now that the tools are installed, Module 2 walks through the daily Git cycle: initialising a repository, staging, committing with messages worth reading, reading history, and ignoring files that should never be committed.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.