The Time Machine
for Code
Git is a distributed version control system. It allows humans to track changes in computer files and coordinate work on those files among multiple people.
Think of it as a "save game" system for your project. You can save your progress (commit), create parallel universes to experiment (branch), and merge those universes back together. GitHub acts as the cloud storage for these histories.
A Bit of History
Git was born out of frustration. In 2005, the relationship between the Linux kernel community and their previous VCS provider (BitKeeper) broke down.
Linus's Criteria
- Speed (Fast enough to handle the Linux Kernel).
- Simple design.
- Strong support for non-linear development (thousands of parallel branches).
- Fully distributed (no central server required).
"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'Git'."
— Linus Torvalds
(British slang for "unpleasant person")
Getting Started
Git works everywhere. Select your operating system to see specific installation instructions.
1. Download Git Bash
For Windows, we strongly recommend Git Bash. It provides a standard Unix-like environment. Go to git-scm.com and download the installer.
Tip: During install, choose "Git from the command line and also from 3rd-party software".
2. Verify
The Three States
Git architecture is defined by three areas: the Working Directory (where you edit), the Staging Area (what you plan to save), and the Repository (history).
Snapshots, Not Deltas
Unlike other VCS systems which store changes as a list of file-based changes (deltas), Git thinks of its data more like a series of snapshots of a miniature filesystem.
The "Delta" Way
The Git Way (Snapshots)
Branching Logic
Branching means you diverge from the main line of development and continue to do work without messing with that main line.
Main vs. Master
They are aliases for the exact same thing: the default branch.
master: Legacy name
(2005-2020).
main: Modern standard (2020+) for inclusive
terminology.
Feature Branch Workflow
Think of feature branches as photocopies of your project. You scribble notes (commits) on the copy, and only when it's perfect do you staple (merge) it into the final report (main).
The HEAD Pointer
How does Git know what branch you are on? It uses a special pointer called
HEAD. In Git, HEAD is just a reference to the current commit you
are viewing.
Usually, HEAD points to a Branch name (like master), which points to a Commit.
If you checkout a specific commit hash directly, you enter "Detached HEAD" state.
Merge Conflicts
When two branches modify the same lines of the same file, Git doesn't know which one is correct. It pauses the merge and asks you to resolve it.
Git inserted markers. Delete them and pick the code you want.
Cherry-pick & Rebase
Git Cherry-pick
Taking a single specific commit from one branch and applying it to another, without merging the whole branch.
Git Rebase
Rewriting history by moving the base of your branch to the tip of another, creating a linear history.
GitHub as Remote
Git is the tool running on your machine. GitHub is a hosting service for Git repositories.
Deployment Guide
Initialize & Commit
Turn your folder into a Git repository and save your first version.
Branch Naming
Ensure you are using the modern 'main' branch name.
Link Remote
Connect your local folder to the empty repository you created on GitHub.
Push to Cloud
Upload your code. The '-u' flag saves the connection for future pushes.
Git Command Guide
Starting Out
Initializes a new Git repository. Creates a .git folder.
Copies an entire repository from a remote source (like GitHub) to your machine.
Sets your identity for commits.
Saving Changes
Shows the state of the working directory and staging area.
Adds files to the staging area (index).
Saves the staged snapshot to the repository history.
Branching & Merging
Lists your branches. git branch [name] creates one.
Switches to another branch.
Combines the specified branch's history into the current branch.
Sharing & Updating
Uploads local branch commits to the remote repository.
Downloads history from the remote but does not merge it.
Fetches and merges changes from the remote to your local branch.
Shows the commit history.
Key Definitions
Version Control System (VCS)
A system that records changes to a file or set of files over time so that you can recall specific versions later.
Git
A distributed version control system for tracking changes in source code during software development.
Repository (Repo)
A data structure used by a VCS to store metadata for a set of files and directories.
Commit
A snapshot of your entire project at a specific point in time.
Branch
A parallel version of a repository. It is contained within the repository, but does not affect the primary or master branch.
Staging Area (Index)
A file that maintains a list of files which are getting ready to be committed.
Merge
Taking the changes from one branch (or commit) and integrating them into another.
Clone
A copy of an existing Git repository.
Pull
Fetching from and integrating with another repository or a local branch.
Push
Uploading local repository content to a remote repository.