Git Glossary
Git has its own vocabulary. This page defines the terms used throughout the course; come back whenever a word is unclear.
Core concepts
| Term | Meaning |
|---|---|
| Repository (repo) | A project folder plus its .git directory, which holds the whole history |
| Working tree (working folder) | The files you see and edit |
| Index / staging area | The list of changes that will go into the next commit |
| Commit | A snapshot of the project with an author, date, message and parent commit(s) |
| Hash / SHA | The 40-hex-digit ID of an object, e.g. a commit; usually shortened to 7 characters |
| HEAD | A pointer to what you have checked out: normally the current branch |
| Detached HEAD | HEAD points straight at a commit instead of a branch; new commits belong to no branch |
| Branch | A movable name pointing at a commit, advancing with each new commit |
| Tag | A fixed name for a commit, typically a release (v1.0.0) |
| Ref | Any name that points to an object: branches, tags, HEAD, remote-tracking branches |
| Parent | The previous commit; a merge commit has two (or more) parents |
| Ancestor | Any commit reachable by following parents back |
Changing history
| Term | Meaning |
|---|---|
| Merge | Combine another branch's work into the current branch |
| Fast-forward | A merge that only moves the branch pointer, creating no merge commit |
| Merge conflict | Both sides changed the same lines; you must choose the result |
| Rebase | Re-apply commits on top of another base, producing new commits and a linear history |
| Cherry-pick | Copy the change of a single commit onto the current branch |
| Revert | Create a new commit that undoes an earlier one |
| Reset | Move the current branch to another commit (optionally changing the index and files) |
| Amend | Replace the last commit with a corrected one |
| Squash | Combine several commits into one |
| Stash | A shelf for uncommitted changes |
| Reflog | A local log of where HEAD and branches have pointed, used to recover "lost" commits |
Working with others
| Term | Meaning |
|---|---|
| Remote | Another copy of the repository, usually on a server; the default name is origin |
| Clone | Make a complete local copy of a remote repository |
| Fetch | Download new commits from a remote without changing your branches |
| Pull | Fetch, then merge (or rebase) into the current branch |
| Push | Upload your commits to a remote branch |
| Upstream / tracking branch | The remote branch your local branch is linked to (origin/main) |
| Remote-tracking branch | Your local, read-only copy of a remote branch's position, like origin/main |
| Fork | Your own server-side copy of someone else's repository |
| Pull request (PR) / merge request (MR) | A request to merge a branch, with review and discussion |
| Bare repository | A repository without a working tree, as used on servers |
Seeing the terms in a real repository
Most of the vocabulary maps directly onto files and commands. Here are HEAD, a branch, a tag, a remote and a remote-tracking branch in one small repository:
git init -q --bare ~/server.git
mkdir demo && cd demo && git init -q
echo "hi" > a.txt && git add . && git commit -q -m "First commit"
git tag v1.0
git remote add origin ~/server.git
git push -q -u origin main
echo "HEAD file: $(cat .git/HEAD)"
echo "main ref: $(git rev-parse --short main)"
echo "tag v1.0: $(git rev-parse --short v1.0)"
echo "remote: $(git remote)"
echo "upstream: $(git rev-parse --abbrev-ref main@{upstream})"
git log --oneline --decorateHEAD file: ref: refs/heads/main
main ref: 4da73dd
tag v1.0: 4da73dd
remote: origin
upstream: origin/main
4da73dd (HEAD -> main, tag: v1.0, origin/main) First commit
Detached HEAD
Checking out a commit (or tag) instead of a branch "detaches" HEAD. You can look around and even commit, but those commits are not on any branch until you create one:
mkdir demo && cd demo && git init -q
echo "1" > n.txt && git add . && git commit -q -m "One"
echo "2" > n.txt && git commit -q -am "Two"
git switch --detach HEAD~1
git status | head -1
git switch -q main
git status | head -1HEAD is now at 1ae3714 One
HEAD detached at 1ae3714
On branch main
Plumbing vs porcelain
Git's commands come in two layers. Porcelain commands (add, commit, log, merge) are meant for people. Plumbing commands (cat-file, hash-object, rev-parse, update-ref) are low-level building blocks with stable output for scripts. The Internals lesson uses plumbing to look inside the .git folder.
Test yourself
What is origin?
- The first commit
- The default name for the remote you cloned from
- The main branch
- A special tag
What is the difference between fetch and pull?
- None
- fetch downloads without changing your branches; pull fetches and then merges or rebases
- pull downloads only tags
- fetch uploads commits
What is a bare repository?
- One with no commits
- One without a working tree, typically used on servers
- One without branches
- A repository with no remote