Git Glossary

This glossary explains common Git terms and gives short command examples for quick reference.

Core Concepts

Repository

A repository is a project directory tracked by Git. It contains your working files and the complete version history stored in the .git directory.

git init
git clone https://github.com/user/repo.git

Commit

A commit is a saved snapshot of staged changes. Each commit has a unique hash, an author, a timestamp, and a message.

git add src/app.js
git commit -m "Add login form"

Branch

A branch is a movable pointer to a commit. Branches let you work on features, fixes, or experiments without changing the main line of development.

git branch feature-login
git switch feature-login

HEAD points to the commit currently checked out in your working tree. In normal work it points to the latest commit of the current branch.

git log HEAD
git show HEAD~1

Working Tree

The working tree is the set of files you can edit directly. It may contain tracked, modified, staged, and untracked files.

git status

Staging Area

The staging area, also called the index, holds changes that will be included in the next commit.

git add file.txt
git restore --staged file.txt

Daily Workflow

Add

git add moves changes from the working tree into the staging area.

git add README.md
git add .

Status

git status shows the current branch, staged changes, unstaged changes, and untracked files.

git status

Diff

git diff shows changes between the working tree, the staging area, commits, or branches.

git diff
git diff --staged
git diff main..feature-login

Log

git log displays commit history.

git log
git log --oneline --graph --decorate

Branching And Merging

Checkout

git checkout can switch branches or restore files. In newer Git versions, prefer git switch for branches and git restore for files.

git checkout main
git checkout -- file.txt

Switch

git switch changes the current branch.

git switch main
git switch -c feature-login

Merge

git merge integrates changes from another branch into the current branch.

git switch main
git merge feature-login

Fast-Forward Merge

A fast-forward merge happens when the target branch has no new commits of its own, so Git can simply move the branch pointer forward.

Three-Way Merge

A three-way merge uses two branch tips and their common ancestor to combine changes. It creates a merge commit when a fast-forward is not possible.

Merge Conflict

A merge conflict happens when Git cannot automatically combine changes. You must edit the conflicted files, stage them, and complete the merge.

git status
git add resolved-file.txt
git commit

Rebase

git rebase reapplies commits on top of another base commit. It is often used to keep feature branches up to date with main.

git switch feature-login
git rebase main

Cherry-Pick

git cherry-pick applies one specific commit to the current branch.

git cherry-pick abc1234

Remote Collaboration

Remote

A remote is a named reference to another repository, usually hosted on a service such as GitHub or GitLab.

git remote -v
git remote add origin https://github.com/user/repo.git

Origin

origin is the default name Git gives to the remote repository you cloned from.

Upstream

An upstream branch is the remote branch tracked by a local branch. It lets Git know where to pull from and push to by default.

git push -u origin feature-login

Fetch

git fetch downloads remote commits and branch references without merging them into your current branch.

git fetch origin

Pull

git pull fetches remote changes and then integrates them into the current branch.

git pull origin main

Push

git push uploads local commits to a remote repository.

git push origin main

Pull Request

A pull request is a review workflow used by hosting platforms. It proposes merging changes from one branch into another.

Fork

A fork is a personal copy of a repository on a hosting platform. It is commonly used for open-source contributions.

Undo And Recovery

Restore

git restore discards or unstages changes.

git restore file.txt
git restore --staged file.txt

Reset

git reset moves the current branch pointer. Depending on the mode, it can also update the staging area and working tree.

git reset --soft HEAD~1
git reset --mixed HEAD~1

Revert

git revert creates a new commit that undoes an earlier commit without rewriting history.

git revert abc1234

Stash

git stash temporarily saves uncommitted changes so you can switch context.

git stash
git stash pop
git stash list

Reflog

git reflog records recent movements of HEAD and branch references. It is useful for recovering commits after an accidental reset or rebase.

git reflog

Tags And Metadata

Tag

A tag is a fixed reference to a commit, often used for releases.

git tag v1.0.0
git tag -a v1.0.0 -m "Release version 1.0.0"

Annotated Tag

An annotated tag stores extra metadata, including tagger, date, and message. It is recommended for release tags.

Lightweight Tag

A lightweight tag is a simple name pointing to a commit, without extra metadata.

SHA

Git uses SHA hashes to identify objects such as commits, trees, and blobs.

Blob

A blob is the Git object type used to store file contents.

Tree

A tree is the Git object type used to store directory structure.

Project Hygiene

Gitignore

.gitignore lists files and directories Git should ignore.

node_modules/
.env
*.log

Hook

A hook is a script Git runs automatically during certain events, such as before a commit or before a push.

Common hooks include:

  • pre-commit
  • commit-msg
  • pre-push

Submodule

A submodule lets one Git repository include another repository at a specific commit.

git submodule add https://github.com/user/lib.git lib

Worktree

A worktree lets you check out multiple branches of the same repository into separate directories.

git worktree add ../feature-login feature-login

Quick Command Reference

git init
git clone <url>
git status
git add <file>
git commit -m "message"
git log --oneline
git switch -c <branch>
git merge <branch>
git fetch
git pull
git push
git stash
git revert <commit>