<!--order=1-->
<h1>Git: Getting Started</h1>
<p>Git is a distributed version control system. Every working copy is a full repository with complete history — there's no central server required, though one is often used for collaboration. This covers the commands you'll use first: setting up a repo, configuring Git, and understanding the working tree.</p>

<h2>Commands Covered</h2>
<p><code>git init</code> · <code>git clone</code> · <code>git config</code> · <code>git status</code> · <code>git help</code> · <code>git version</code></p>

<h2>git init</h2>
<p>Creates a new empty Git repository in the current directory (or a specified path). Git stores everything in a <code>.git/</code> subdirectory.</p>
<pre>
# Initialize a repo in the current directory
$ git init

# Initialize a named directory (creates it if it doesn't exist)
$ git init my-project

# Initialize a bare repository (no working tree — used for servers/remotes)
$ git init --bare my-project.git
</pre>
<p>After <code>git init</code>, the directory contains a <code>.git/</code> folder but no commits yet. The repository is empty until you add and commit files.</p>

<h2>git clone</h2>
<p>Copies an existing repository — full history included. The clone knows about the original (called <code>origin</code>) and can push/pull changes to it.</p>
<pre>
# Clone from GitHub (HTTPS)
$ git clone https://github.com/user/repo.git

# Clone into a specific directory name
$ git clone https://github.com/user/repo.git my-local-name

# Clone via SSH (requires SSH key set up with GitHub/GitLab)
$ git clone git@github.com:user/repo.git

# Shallow clone — only the latest commit (faster, less disk)
$ git clone --depth 1 https://github.com/user/repo.git

# Clone a specific branch
$ git clone --branch develop https://github.com/user/repo.git

# Clone a local repository
$ git clone /path/to/existing/repo new-copy
</pre>

<h2>git config</h2>
<p>Gets and sets configuration values. Config is layered: system-wide, per-user (<code>~/.gitconfig</code>), and per-repo (<code>.git/config</code>). Per-repo overrides per-user, which overrides system.</p>
<pre>
# Set your identity (required before your first commit)
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"

# Set your default editor (used for commit messages)
$ git config --global core.editor vim
$ git config --global core.editor "nano"
$ git config --global core.editor "code --wait"   # VS Code

# Set default branch name for new repos
$ git config --global init.defaultBranch main

# Enable coloured output
$ git config --global color.ui auto

# Set up a credential helper (avoids re-entering password)
$ git config --global credential.helper store       # saves to disk (plain text)
$ git config --global credential.helper cache       # saves in memory for 15min
$ git config --global credential.helper 'cache --timeout=3600'

# View all current config values
$ git config --list
$ git config --list --show-origin   # shows which file each setting comes from

# Read a specific value
$ git config user.email

# Set a per-repo setting (omit --global)
$ git config user.email "work@company.com"

# Create an alias (shortcut for a command)
$ git config --global alias.st status
$ git config --global alias.co checkout
$ git config --global alias.lg "log --oneline --graph --decorate"
$ git st    # now runs: git status
</pre>

<h2>git status</h2>
<p>Shows the state of the working tree and staging area — which files are modified, staged, or untracked. Run this constantly.</p>
<pre>
$ git status

# Short format (compact output)
$ git status -s
# Output columns: XY filename
#   X = staging area status
#   Y = working tree status
#   M = modified, A = added, D = deleted, ? = untracked, ! = ignored

$ git status --short --branch   # include current branch in short format
$ git status --ignored          # also show ignored files
</pre>

<table>
  <thead><tr><th>Symbol</th><th>Meaning</th></tr></thead>
  <tbody>
    <tr><td><code>M</code> (left)</td><td>Staged (modified in index vs last commit)</td></tr>
    <tr><td><code>M</code> (right)</td><td>Unstaged (modified in working tree vs index)</td></tr>
    <tr><td><code>A</code></td><td>Newly staged file</td></tr>
    <tr><td><code>D</code></td><td>Deleted</td></tr>
    <tr><td><code>R</code></td><td>Renamed</td></tr>
    <tr><td><code>??</code></td><td>Untracked file</td></tr>
    <tr><td><code>!!</code></td><td>Ignored file</td></tr>
  </tbody>
</table>

<h2>git help</h2>
<pre>
# Open the man page for a command
$ git help commit
$ git help log

# Short summary (one-liners for all commands)
$ git help --all
$ git help -a          # same

# List conceptual guides (not commands)
$ git help --guides
$ git help -g

# Open a specific guide
$ git help revisions    # how to specify commits/ranges
$ git help hooks        # how hooks work
$ git help attributes   # .gitattributes format
</pre>

<h2>git version</h2>
<pre>
$ git version
# git version 2.47.0

# Useful when troubleshooting — some features require specific versions.
# Git 2.23+ introduced git switch and git restore as clearer alternatives
# to the overloaded git checkout command.
</pre>

<h2>The Three Areas</h2>
<p>Understanding Git's three areas is fundamental to everything else:</p>
<table>
  <thead><tr><th>Area</th><th>What it is</th><th>Commands that affect it</th></tr></thead>
  <tbody>
    <tr><td>Working tree</td><td>Files on disk as you edit them</td><td>Your editor, <code>git restore</code></td></tr>
    <tr><td>Staging area (index)</td><td>Snapshot queued for the next commit</td><td><code>git add</code>, <code>git rm</code>, <code>git restore --staged</code></td></tr>
    <tr><td>Repository (.git/)</td><td>Committed history — permanent record</td><td><code>git commit</code>, <code>git reset</code></td></tr>
  </tbody>
</table>

<h2>References</h2>
<ul>
  <li><a href="https://git-scm.com/docs/git-init" target="_blank" rel="noopener">git-init documentation ↗</a></li>
  <li><a href="https://git-scm.com/docs/git-clone" target="_blank" rel="noopener">git-clone documentation ↗</a></li>
  <li><a href="https://git-scm.com/docs/git-config" target="_blank" rel="noopener">git-config documentation ↗</a></li>
  <li><a href="https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup" target="_blank" rel="noopener">Pro Git Book — First-Time Setup ↗</a></li>
</ul>
