Shattered Vales Studio Inc.

Git Fundamentals: How Git Actually Works

Most Git confusion comes from memorizing commands without a picture of what they do. This guide builds that picture: where your changes live, what a commit and a branch really are, and how your computer and GitHub stay in sync. Read it before the Daily Git Terminal Workflow, and everything there will make sense.

Step 1: Know What Git Is (and Isn't)

Git is a version control system: it records snapshots of a project over time, so you can see what changed, who changed it, why, and go back to any earlier state. It runs entirely on your computer. Every clone holds the project's complete history, so you can commit, browse history, and create branches with no network connection.

GitHub is a website that hosts Git repositories and adds collaboration on top: pull requests, code review, issues, and CI. Git is the tool; GitHub is where the team's shared copy lives. You can use Git without GitHub, but not the other way round.

Step 2: Learn the Three Places Your Changes Live

Every change you make moves through three areas. Almost every Git command moves changes from one area to another, so this is the single most useful idea in Git.

  Working tree            Staging area              Repository
  (your files on disk)    (the "next commit")       (.git folder: history)

   edit files  ──── git add ────▶  staged  ──── git commit ────▶  committed
       ◀──── git restore ────      ◀──── git restore --staged ────

git status shows exactly what is in each area: "Changes not staged" is the working tree, "Changes to be committed" is the staging area.

Step 3: Understand Commits

A commit is a snapshot of the whole project at one moment, plus a little metadata: the author, the date, the message, and a link to the commit before it (its parent). Those parent links chain commits into a history.

Each commit is identified by a hash: a 40-character ID such as 3f2a9c1e…, usually shortened to the first 7 characters. The hash is computed from the commit's contents, so a commit can never be changed. Commands that seem to "edit" commits (amend, rebase) actually create new commits with new hashes and leave the old ones behind.

git log --oneline           # one line per commit: short hash and message
git show 3f2a9c1            # what one commit changed, and its details

Step 4: Understand Branches and HEAD

A branch is not a copy of your files. It is just a label that points at one commit. When you commit on a branch, the label moves forward to the new commit. That's why creating a branch is instant and free.

HEAD means "where you are right now". Normally it points at a branch, which points at a commit. git switch moves HEAD to another branch and updates your working tree to match.

                         ┌── feature/issue-42   ◀── HEAD (you are here)
                         ▼
          A ── B ── C ── F ── G
                    ▲
                    └── Dev

Here Dev points at commit C. You branched from C and made commits F and G, so feature/issue-42 points at G. Dev hasn't moved; your work stays separate until it is merged.

Step 5: Understand Remotes: Your Copy and GitHub's

A remote is another copy of the repository, normally the one on GitHub. When you clone, Git names it origin. Your clone keeps remote-tracking branches such as origin/Dev: your machine's last-known snapshot of GitHub's branches. They don't update by themselves.

CommandDirectionWhat it does
git fetchGitHub → youDownloads new commits and updates origin/*. Never changes your branches or files. Always safe.
git pullGitHub → youA fetch, then integrates the remote branch into your current branch (by rebase, with the studio settings).
git pushYou → GitHubUploads your new commits and moves the branch on GitHub to match yours.
git cloneGitHub → youCreates a new local copy with the full history. Done once per repository.
git remote -v               # where origin points
git branch -a               # local branches plus remote-tracking branches

Step 6: Understand Merging and Rebasing

Sooner or later your branch and Dev both have new commits. There are two ways to combine them.

Before: both branches moved on

          A ── B ── C ── D ── E         Dev
                    └── F ── G         feature/issue-42

Merge: join them with a new merge commit M

          A ── B ── C ── D ── E ── M    Dev
                    └── F ── G ──┘

Rebase: replay F and G on top of E as new commits F′ and G′

          A ── B ── C ── D ── E         Dev
                              └── F′ ── G′   feature/issue-42

Merging keeps history exactly as it happened. Rebasing produces a straight line that's easier to read and review, but it rewrites your commits. That's why the rule is: rebase only your own, unshared branches. At the studio you rebase your feature branch onto Dev, and GitHub merges pull requests for you. When a branch is simply behind with no commits of its own, Git just moves the label forward, which is called a fast-forward.

Step 7: Practice in a Throwaway Repository

The fastest way to understand Git is to watch it. Run these commands one at a time in a scratch folder, and run git status and git log --oneline --graph --all after each one to see what changed.

mkdir git-practice && cd git-practice
git init
echo "hello" > notes.txt
git status                          # notes.txt is untracked
git add notes.txt
git status                          # now staged
git commit -m "docs: add notes"
git switch -c feature/practice
echo "more" >> notes.txt
git commit -am "docs: add more notes"
git switch main                     # "master" if you skipped init.defaultBranch
cat notes.txt                       # "more" is gone; it lives on the other branch
git merge feature/practice          # fast-forward
git log --oneline --graph --all

Delete the folder when you're done. Nothing here touches GitHub. Try breaking things on purpose, then use Undoing Things Safely to recover.

Step 8: Keep the Glossary Handy

TermMeaning
Repository (repo)A project tracked by Git, including its full history.
CloneYour local copy of a remote repository.
CommitA saved snapshot of the project, with a message and a hash.
Hash (SHA)The unique ID of a commit.
BranchA movable label pointing at a commit.
HEADThe commit or branch you currently have checked out.
Staging area / indexThe draft of your next commit.
Remote / originAnother copy of the repository; origin is the default name for GitHub's.
UpstreamThe remote branch your local branch tracks.
MergeCombine two lines of history with a merge commit.
RebaseReplay commits on top of a different starting point.
ConflictTwo changes to the same lines that Git can't combine on its own.
Pull request (PR)A GitHub request to merge one branch into another, with review.
TagA permanent label on a commit, usually a release version.