Master Git & GitHub
Version control is the backbone of every real-world codebase. This guide walks through what Git and GitHub actually are, why every team relies on them, how Git works under the hood, and gives you practical commands, diagrams and a cheat sheet you can come back to any time.
$ git init Initialized empty Git repository $ git add . $ git commit -m "first commit" [main (root-commit) a1b2c3d] first commit
What is Git?
Git is a distributed version control system. It tracks every change made to your files over time, so you can see exactly what changed, when, and by whom — and roll back to any earlier point if something breaks. "Distributed" means every developer has a full copy of the project history on their own machine, not just on a central server.
Git was created by Linus Torvalds in 2005 to manage the Linux kernel's source code, and it has since become the default version control tool across almost every software team in the world.
Tracks history
Every commit is a snapshot you can return to
Enables teamwork
Multiple people can work on the same code safely
Works offline
Full history lives on your own machine
Git & GitHub cheat sheet
The commands you'll reach for most often, grouped by task.
Setup & Config
git initInitialize a new repositorygit clone <url>Copy a remote repo locallygit config --global user.name "Name"Set your namegit config --global user.email "you@mail.com"Set your email
Basic Workflow
git statusShow changed / staged filesgit add <file>Stage a filegit add .Stage everythinggit commit -m "message"Save a snapshotgit log --onelineView commit historygit diffShow unstaged changes
Branching & Merging
git branchList branchesgit checkout -b <name>Create & switch to branchgit switch <name>Switch to existing branchgit merge <branch>Merge branch into currentgit branch -d <name>Delete a merged branch
Remote & Collaboration
git remote add origin <url>Link a remote repogit push -u origin mainPush & track upstreamgit pullFetch + merge from remotegit fetchDownload changes without merging
Undo & Fix Mistakes
git restore <file>Discard unstaged changesgit reset --soft HEAD~1Undo last commit, keep changesgit revert <commit>Create a new commit that undoes onegit stashTemporarily shelve changesgit stash popRe-apply stashed changes
GitHub Specific
gh repo clone <owner/repo>Clone via GitHub CLIgh pr createOpen a pull requestgh pr mergeMerge a pull requestgh issue listList repo issues
Git vs GitHub, at a glance
| Aspect | Git | GitHub |
|---|---|---|
| What it is | A version control tool | A cloud hosting platform for Git repos |
| Runs where | On your local machine | In the cloud, accessed via browser/CLI |
| Needs internet? | No | Yes, for hosting & collaboration features |
| Core unit | Commit | Repository, Pull Request, Issue |
| Collaboration | Manual (patches, shared servers) | Built-in: PRs, reviews, permissions |
| Alternatives | Mercurial, SVN | GitLab, Bitbucket |