Skip to main content

Git Terminology πŸ“š

Understanding Git terminology is crucial for working effectively with version control. This section breaks down all the important terms and concepts you need to know.

Core Concepts​

Repository (Repo) πŸ“¦β€‹

A repository is a directory that contains your project files and Git's tracking information.

my-project/
β”œβ”€β”€ .git/ (Git's internal data)
β”œβ”€β”€ src/
β”œβ”€β”€ README.md
└── ...

Types:

  • Local Repository - On your computer
  • Remote Repository - On a server (like GitHub)

Working Directory πŸ“‚β€‹

The working directory is the actual folder with your files that you're editing.

# Your working directory when you do this:
cd my-project/
# Everything here is your working directory

Staging Area (Index) πŸ“‹β€‹

The staging area is where you prepare changes before committing them. It's an intermediate step between your working directory and repository.

Working Directory  β†’  git add  β†’  Staging Area  β†’  git commit  β†’  Repository
(Your changes) (Stage them) (Ready to save) (Save them) (Stored forever)

Commit πŸ’Ύβ€‹

A commit is a snapshot of your project at a specific point in time. Each commit includes:

  • Snapshot of all files
  • Author information (name, email)
  • Timestamp when created
  • Commit message describing changes
  • Parent commit (previous version)
# Create a commit
git commit -m "Add user authentication feature"

# Commit hash (unique identifier)
# Example: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0

Hash/SHA βœοΈβ€‹

Every commit has a unique hash (a 40-character alphanumeric string):

# Full hash (SHA-1)
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0

# Short hash (usually first 7 characters)
a1b2c3d

# Both identify the same commit
git show a1b2c3d # Works with short hash
git show a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0 # Works with full

Branches & References​

Branch πŸŒ³β€‹

A branch is an independent line of development. It's essentially a pointer to a specific commit.

main branch:    ──o──o──o  (stable code)
└──o──o──o feature branch (new feature)
└──o bugfix (another feature)

Default branch is usually main or master.

HEAD βš‘β€‹

HEAD is a special pointer that indicates which branch/commit you're currently on.

# HEAD points to current branch
# Usually: main, feature-branch, etc.

# See where HEAD points
cat .git/HEAD
# Output might be: ref: refs/heads/main

Detached HEAD πŸ”Œβ€‹

When HEAD points directly to a commit instead of a branch:

# This creates detached HEAD state
git checkout a1b2c3d

# Get back to a branch
git checkout main

Upstream Branch πŸŒŠβ€‹

The upstream branch is the remote branch your local branch tracks.

# Check upstream
git branch -vv

# Output example:
# main a1b2c3d [origin/main] Your commit message
# feature-name x1y2z3d [origin/feature-name] Another message

# The part in brackets is your upstream branch

Tracking Branch πŸŽ―β€‹

A tracking branch is a local branch connected to a remote branch.

# Create tracking branch
git checkout --track origin/feature-name

# Or set upstream for existing branch
git branch -u origin/main

Remote Operations​

Remote πŸŒβ€‹

A remote is a reference to a repository hosted somewhere else (like GitHub).

# List remotes
git remote -v

# Output example:
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
# upstream https://github.com/original/repo.git (fetch)

# Common remote names:
# - origin: your fork
# - upstream: original repository

Clone πŸ“₯​

Cloning downloads a repository from remote to your computer, including full history.

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

# Creates:
# - Local copy of all files
# - Complete commit history
# - Configured remote "origin"

Push πŸ“€β€‹

Pushing uploads your local commits to a remote repository.

git push origin main

# Sends your commits to remote "origin" on branch "main"

Pull πŸ“₯⬆️​

Pulling fetches remote changes and merges them into your local branch.

git pull origin main

# Equivalent to:
# git fetch origin main
# git merge origin/main

Fetch πŸ”β€‹

Fetching downloads changes from remote without merging them.

git fetch origin

# Downloads all new commits from remote
# Updates your local tracking branches
# Doesn't change your working directory

Merging & History​

Merge πŸ”€β€‹

Merging combines changes from one branch into another.

# Merge feature into main
git checkout main
git merge feature

# Creates merge commit (usually)
# Combines all changes

Fast-Forward ⏭️​

A fast-forward merge happens when the target branch hasn't changed since the source branch was created.

main:     o──o──o
└──o──o──o feature

# Fast-forward (no merge commit):
main: o──o──o──o──o──o

# Regular merge (creates merge commit):
main: o──o──o──────o (merge commit)
└──o──o──oβ”€β”˜

Conflict βš οΈβ€‹

A merge conflict occurs when Git can't automatically combine changes:

<<<<<<< HEAD
Your version
=======
Their version
>>>>>>> feature-branch

You must manually resolve conflicts before completing the merge.

Rebase πŸ”„β€‹

Rebasing re-applies commits from one branch onto another. It rewrites history.

Before rebase:
main: o──o──o
└──o──o feature

After rebase onto main:
main: o──o──o
└──o──o feature

Cherry-pick πŸ’β€‹

Cherry-picking copies specific commits from one branch to another.

# Copy commit a1b2c3d to current branch
git cherry-pick a1b2c3d

# Useful for applying specific fixes to multiple branches

Advanced Concepts​

Stash πŸ“¦β€‹

Stash temporarily saves changes without committing them.

# Save current changes
git stash

# Your working directory is clean
# Changes stored in stash

# Restore changes later
git stash pop

Tag πŸ·οΈβ€‹

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

# Create lightweight tag
git tag v1.0.0

# Create annotated tag (with message)
git tag -a v1.0.0 -m "Release version 1.0.0"

# Push tags to remote
git push origin v1.0.0

Ref πŸŽ―β€‹

A ref is any name that points to a commit:

  • Branches (refs/heads/main)
  • Tags (refs/tags/v1.0.0)
  • HEAD
  • Remote branches (refs/remotes/origin/main)

Reflog πŸ”β€‹

Reflog (reference log) records where HEAD has pointed.

# View reflog
git reflog

# Output example:
# a1b2c3d HEAD@{0}: commit: Add feature
# x1y2z3d HEAD@{1}: merge origin/main
# m1n2o3p HEAD@{2}: checkout: switching to main

# Recover lost commits
git checkout HEAD@{1}

Terminology Summary Table πŸ“Šβ€‹

TermDefinitionExample
RepositoryProject folder with Git tracking.git folder
CommitSnapshot with message and metadataa1b2c3d
BranchIndependent line of developmentmain, feature
HEADCurrent position in repositoryPoints to main
Staging AreaIntermediate step before commitgit add puts here
RemoteExternal repository referenceorigin, upstream
PushUpload to remotegit push origin main
PullDownload & merge from remotegit pull origin main
MergeCombine branchesgit merge feature
RebaseRe-apply commitsgit rebase main
StashTemporarily save changesgit stash pop
TagNamed reference to commitv1.0.0 release

Common Phrases You'll Hear πŸ‘‚β€‹

"Commit to a branch"​

Means you're creating commits that belong to that branch.

"Push to origin"​

Means you're uploading commits to the remote named "origin".

"Merge into main"​

Means you're combining changes from another branch into the main branch.

"Check out a branch"​

Means you're switching to that branch to work on it.

"Rebase onto main"​

Means you're re-applying your commits on top of main's latest commits.

"Stash changes"​

Means you're temporarily saving uncommitted changes.

"Cherry-pick a commit"​

Means you're copying a specific commit to your current branch.

Visual Reference πŸ“β€‹

Repository Flow:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Working │──add──→│ Staging │──commit──→│ Repository β”‚
β”‚ Directory β”‚ β”‚ Area β”‚ β”‚ (History) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Branch Structure:
main
↓
o─────o─────o
β†—
/ feature
o───o───o
/
o bugfix

Remote Operations:
Local Repository ←──fetch/pull── Remote Repository
Local Repository ──push──→ Remote Repository

Now that you understand the terminology, you're ready to learn about Branches and how to work with them effectively!

Next: Branches Explained 🌳