← Back to Git Course | Chapter 10: Tools & Internals | Lesson 8 of 8

Git Glossary

A Git glossary is like a picture dictionary for the new words in Git, such as working folder, staging area and commit, so you know what people mean.

Working Directory and Staging Area

The working directory is the actual files on disk that you edit directly, while the staging area (also called the index) is a separate holding zone where you place exactly the changes you want in your next commit. Running git add moves a change from the working directory into the staging area, and only staged changes get included when you run git commit.

Example: Working Directory and Staging Area

bash
git add file.txt
git status

HEAD and Detached HEAD

HEAD is a pointer to whichever commit you currently have checked out, and it normally points to a branch name rather than a commit directly, so committing moves both HEAD and the branch forward together. Checking out a specific commit hash instead of a branch puts you in detached HEAD state, where new commits aren't attached to any branch and can be lost once you switch away unless you create a branch to save them.

Example: HEAD and Detached HEAD

bash
git checkout a1b2c3d
# HEAD is now detached, pointing directly at a1b2c3d

Upstream and Tracking Branches

An upstream branch is the remote branch a local branch is configured to push to and pull from by default, set either at clone time or explicitly with git branch --set-upstream-to. Once set, plain git push and git pull with no arguments know exactly which remote branch to talk to, and Git can tell you how many commits your local branch is ahead or behind it.

Example: Upstream and Tracking Branches

bash
git branch --set-upstream-to=origin/main main
git push
git pull

Fast-Forward vs Merge Commit

A fast-forward merge happens when the target branch has no new commits since it diverged, so Git simply moves the branch pointer forward to match the incoming branch with no new commit created. A merge commit happens when both branches have diverged with their own new commits, so Git creates a new commit with two parents to tie the histories back together, visible as a fork-and-rejoin shape in the log graph.

Example: Fast-Forward vs Merge Commit

bash
git merge feature-x
# fast-forward if main has no new commits, else a merge commit

Commit Hash and Ancestors

Every commit is identified by a SHA-1 hash computed from its content, parent commit, author, and message, which is why changing anything about a commit produces a different hash. An ancestor commit is any commit reachable by following parent links backward from a given commit, and Git's relative references like HEAD~1 or HEAD~3 walk that ancestor chain a fixed number of steps.

Example: Commit Hash and Ancestors

bash
git log --oneline
git log a1b2c3d --oneline
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Mixing up the working directory and the staging area, and assuming changes are staged when they are only saved on disk.
  2. Thinking HEAD always means the latest commit on main, when it points to whatever is currently checked out.
  3. Confusing origin with upstream, when origin is your default remote and upstream often names the original project of a fork.
Chapter Summary
  • GUI tools and editor integrations offer alternatives to the command line.
  • The Git object model, git gc, and maintenance explain how Git stores data.
  • Git LFS, .gitattributes, and a glossary support larger projects and terminology.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.