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 πβ
| Term | Definition | Example |
|---|---|---|
| Repository | Project folder with Git tracking | .git folder |
| Commit | Snapshot with message and metadata | a1b2c3d |
| Branch | Independent line of development | main, feature |
| HEAD | Current position in repository | Points to main |
| Staging Area | Intermediate step before commit | git add puts here |
| Remote | External repository reference | origin, upstream |
| Push | Upload to remote | git push origin main |
| Pull | Download & merge from remote | git pull origin main |
| Merge | Combine branches | git merge feature |
| Rebase | Re-apply commits | git rebase main |
| Stash | Temporarily save changes | git stash pop |
| Tag | Named reference to commit | v1.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 π³