Two tools, one workflow
Before installing anything, it helps to know exactly what each tool does — and why professional workflows always use both together.
What is Git?
A distributed version control system that runs on your machine. Created by Linus Torvalds in 2005 to manage Linux kernel development — now the standard everywhere.
- Records every change, with a message explaining why
- Lets you branch off and experiment safely
- Merges work back together automatically
- Can revert any file to any past state
What is GitHub?
A cloud platform that hosts Git repositories. Git is the tool on your computer; GitHub is the server where that history is stored and shared.
- Remote repositories, backed up automatically
- Pull requests for reviewing changes
- Issues for tracking bugs and features
- Actions for automated testing & deploys
Why both?
Git alone means your history lives on one machine — if it fails, you lose everything. GitHub needs Git underneath it to receive anything at all.
- You commit locally with Git, constantly
- You push to GitHub, periodically
- Together: safe, shared, professional
Inside the four layers
This whole page reads Git the way Git actually works: as physical depth. Every command below moves a file forward or backward between four real layers. Click one to bring it to the front.
Working Directory
UnstagedThe nearest layer — the actual files in your project folder, exactly as your editor last saved them. Git is watching this folder, but nothing here is protected yet: an accidental overwrite or delete is real damage.
git status
Which files changed since the last commit.
git add <file>
Stages a snapshot of the file for the next commit.
Staging Area
StagedAlso called the index. A curated snapshot, separate from what's on disk — it holds exactly what the next commit will contain, no more and no less. This is what lets you commit half your changes and keep working on the rest.
git restore --staged <file>
Unstages the file without discarding the edit.
git commit -m "…"
Seals the staged snapshot into permanent history.
Local Repository
CommittedThis is what "Git" actually is — every commit you've ever made, stored in the hidden .git/ folder on this machine. It's a complete, self-contained history; nothing here needs the internet.
git log --oneline
The commit history, one line per snapshot.
git push origin main
Sends new commits up to GitHub.
GitHub (Remote)
PushedThe farthest layer — the same history, hosted on GitHub's servers. Backed up, shareable with one link, and the copy every collaborator pulls from. Parts 2 and 3 of this guide are entirely about wiring your machine up to this layer.
git clone <url>
First time only — downloads the whole repository.
git pull
Brings GitHub's commits down into your local repository.
Install Git
First, check whether Git is already on your machine.
# check for an existing install
git --version
If Git is installed you'll see something like git version 2.44.0. If not, follow your platform below.
macOS ships an old Git via Apple's developer tools. Fast to get, but it lags behind the latest release.
- 1Open Terminal.
⌘+Space → type Terminal → Return. Or Finder → Applications → Utilities → Terminal.
- 2Trigger the installer.
Run git --version. If Git is missing, macOS shows a dialog: "The xcode-select command requires the command line developer tools." Click Install — not Get Xcode.
- 3Wait for the download.
About 150–200 MB, typically 2–5 minutes depending on your connection.
- 4Accept the licence agreement.
- 5Confirm it worked.
git --version # Expected: git version 2.x.x (Apple Git-xxx)
Homebrew is macOS's most popular package manager — gives you the latest Git, updatable with one command.
- 1Install Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It will ask for your system password. Nothing appears as you type — that's normal.
- 2Apple Silicon: add Homebrew to your PATH.
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"
- 3Install Git.
brew install git
- 4Confirm.
git --version # Expected: git version 2.x.x (NOT Apple Git) - 5Update later, anytime.
brew upgrade git
If git --version still says Apple Git, run which git. If it shows /usr/bin/git instead of /opt/homebrew/bin/git, reopen your terminal — or see Troubleshooting.
Git for Windows bundles Git, a Bash emulator (Git Bash), and a GUI tool.
- 1Download.
Go to git-scm.com/download/win and get the 64-bit installer.
- 2Run it.
Open the .exe, click Yes on the UAC prompt.
- 3Licence, destination, components.
Accept the defaults and click Next through each.
- 4Default editor.
Change from Vim to VS Code, Notepad++, or Nano.
- 5Initial branch name.
Choose Override and type main.
- 6PATH environment — critical.
Select "Git from the command line and also from 3rd-party software." This makes git work in PowerShell, Command Prompt, and VS Code.
- 7SSH.
Select "Use bundled OpenSSH."
- 8HTTPS backend.
Select "Use the OpenSSL library."
- 9Line endings — critical.
Select "Checkout Windows-style, commit Unix-style line endings." Prevents false diffs when collaborating across platforms.
- 10Terminal.
Select "Use MinTTY."
- 11git pull behaviour.
Keep the default.
- 12Credential helper.
Select "Git Credential Manager," then Install.
- 13Verify.
Open Git Bash from the Start Menu:
git --version # Expected: git version 2.x.x.windows.x
Open PowerShell as Administrator:
winget install --id Git.Git -e --source winget
Restart your terminal, then confirm with git --version.
Create a GitHub account
Git manages history locally. A GitHub account gives that history a home online — backed up, accessible anywhere, and shareable with one link.
Your username becomes part of every URL tied to your work:
Pick something professional (based on your real name), short and memorable, consistent with LinkedIn, and free of random numbers unless necessary.
- 1Go to github.com in any browser.
- 2Click "Sign up" top-right.
- 3Enter your email address.
Use the same one you'll configure Git with in Part 3 — otherwise commits won't link to your profile.
- 4Create a password of at least 8 characters — ideally from a password manager.
- 5Choose your username.
Effectively permanent — changing it later breaks links to your existing repositories.
- 6Email preferences.
Optional — your call on product updates.
- 7Solve the CAPTCHA.
- 8Click "Create account."
GitHub sends a verification email.
- 9Verify your email.
Click the link in the email — some features stay locked until you do.
- 10Onboarding survey.
Optional — only affects the tips GitHub shows you.
Once your email is verified, your account is fully active. Next: connect it to the Git you just installed.
Configure Git
Your name and email are attached to every commit and become a permanent part of project history — like a signature on each saved change.
| Level | Scope | Stored in |
|---|---|---|
| --system | Every user on the machine | /etc/gitconfig (macOS)C:\Program Files\Git\etc\gitconfig |
| --global | Your user, all repositories — used in this guide | ~/.gitconfig |
| --local | One repository only — overrides global | .git/config |
git config --global user.name "Your Full Name" git config --global user.email "youremail@example.com"
Why it matters: every commit says who made it — how teammates identify changes, and part of your professional identity.
The email here must exactly match an email on your GitHub account. It's how GitHub links commits to your profile. Mismatched, and commits show as an "unknown user," are excluded from your contribution graph, and your name won't display correctly.
Check your GitHub emails: github.com/settings/emails
Running git commit without -m opens an editor — the default is Vim, which trips up most beginners.
VS Code (recommended):
git config --global core.editor "code --wait"
The --wait flag pauses Git until you close the tab. Without it, Git continues before you're done writing.
Nano (simple):
git config --global core.editor "nano"
VS Code:
git config --global core.editor "code --wait"
Notepad++:
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Notepad (built-in):
git config --global core.editor "notepad"
Git historically named the first branch master. GitHub and the community now use main — a mismatch will fail your first push.
git config --global init.defaultBranch main
Windows uses CRLF; macOS and Linux use LF. Left unconfigured, Git sees every line as changed across platforms — polluting history.
git config --global core.autocrlf input
Strips CRLF to LF on commit; adds nothing on checkout. Files on disk and in the repo both stay LF.
git config --global core.autocrlf true
Converts LF→CRLF on checkout (for Windows apps) and CRLF→LF on commit (so the repo stays consistent for everyone).
git config --global --list
Expected output:
Or view the file directly:
cat ~/.gitconfig
Verify your setup
Skipping verification is where quiet failures hide: the wrong Git version active, a typo'd email, an editor that isn't installed, a branch still called master. Five minutes now saves hours later.
git --version
Check which binary is active:
which git
Expected: /opt/homebrew/bin/git (Apple Silicon) or /usr/local/bin/git (Intel). /usr/bin/git means Homebrew isn't taking priority — see Troubleshooting.
where git
Expected: a path inside C:\Program Files\Git\. Nothing returned means Git isn't on PATH — re-run the installer.
git config --global user.name git config --global user.email
Spelled correctly? Matches your GitHub account? Rerun the config command to overwrite if not.
git config --global --list
Confirm all five: user.name, user.email, core.editor, init.defaultbranch, core.autocrlf.
- 1Log in at github.com.
- 2Click + → New repository, name it git-test.
- 3Check "Add a README file" and click Create repository.
# clone, change, and push
git clone https://github.com/yourusername/git-test.git
cd git-test
echo "Hello from my machine" >> README.md
git add README.md
git commit -m "Add a test line to README"
git push origin mainWhen prompted for credentials, use your GitHub username and a Personal Access Token as the password (below).
Visit github.com/yourusername/git-test and confirm your commit message appears. Then check your profile's contribution graph — today should be highlighted.
GitHub removed password authentication in August 2021. Use a Personal Access Token (PAT) instead:
- Go to github.com/settings/tokens
- Click Generate new token (classic)
- Set a name, an expiry, and tick the repo scope
- Click Generate token and copy it immediately — shown once only
Use the token as your password when Git prompts. The credential manager saves it after the first time.
Quick reference
Every command from this guide, in one place.
Git setup commands
| Command | What it does |
|---|---|
| git --version | Check installed version |
| which git | Show the active Git binary path |
| where git | Show the active Git binary path |
| git config --global user.name "Name" | Set display name for all commits |
| git config --global user.email "email" | Set email for all commits |
| git config --global core.editor "code --wait" | Set VS Code as commit editor |
| git config --global init.defaultBranch main | New repos start on main |
| git config --global core.autocrlf input | Line endings (macOS/Linux) |
| git config --global core.autocrlf true | Line endings (Windows) |
| git config --global --list | Show all global settings |
First repository workflow
| Command | What it does |
|---|---|
| git clone <url> | Download a repo from GitHub |
| git status | Show changed files |
| git add . | Stage all changes |
| git add <file> | Stage one file |
| git commit -m "message" | Save staged changes with a description |
| git push origin main | Upload commits to GitHub |
| git pull | Download latest commits from GitHub |
| git log --oneline | Compact commit history |
Config file locations
| Platform | Global .gitconfig path |
|---|---|
| macOS | ~/.gitconfig (e.g. /Users/janedoe/.gitconfig) |
| Windows | C:\Users\YourUsername\.gitconfig |
Troubleshooting
The most common failure points, and exactly how to fix each one.
"command not found: git" (macOS)▸
"git is not recognized" (Windows)▸
Homebrew's Git isn't taking priority▸
# Apple Silicon echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc source ~/.zshrc # Intel Mac echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
Push rejected: authentication failed▸
Commits missing from the contribution graph▸
- Run git config --global user.email to see your configured email.
- Check registered emails at github.com/settings/emails.
- If different: git config --global user.email "correct@email.com"
- Future commits link correctly — past ones can't be fixed retroactively.
"refusing to merge unrelated histories"▸
git pull origin main --allow-unrelated-histories
You're set up
Here's what's now in place, and where to go from here.
- ✓Installed Git via Xcode tools or Homebrewvia the official installer or winget
- ✓Created a GitHub account with a professional username and verified email
- ✓Configured Git with name, email, editor, default branch, and line endings
- ✓Verified everything end-to-end — pushed a real commit and confirmed it on GitHub
What to learn next
- The daily add / commit / push cycle
- Branching and merging
- SSH keys, in place of tokens
- Pull requests & code review
- GitHub Actions for automation