Start here if you’re new to Git or need a refresher on core concepts like rebase, merge, conflicts, and branching.
What is Git?
Git is a version control system that tracks changes to your code over time. Think of it as:- A time machine for your code
- A collaboration tool that lets multiple people work on the same codebase
- A safety net that lets you experiment without fear
Core Concepts
Repository (Repo)
A repository is a folder containing your project files plus Git’s tracking data (stored in.git/ folder).
Commit
A commit is a snapshot of your code at a specific point in time. Each commit:- Has a unique ID (hash like
a3f2b9c) - Contains a message describing what changed
- Records who made the change and when
Branch
A branch is an independent line of development. It’s like creating a parallel universe where you can make changes without affecting the main timeline.main branch
The stable, production-ready version of your code
feature branch
Your experimental workspace for new features
Key Operations Explained
Clone
Cloning downloads a repository from GitHub/GitLab to your local machine.Pull
Pulling downloads the latest changes from the remote repository to your local branch.Always pull before starting new work to ensure you have the latest code.
Push
Pushing uploads your local commits to the remote repository (GitHub/GitLab).Add (Staging)
Adding files puts them in the “staging area”—marking them to be included in the next commit.Merge vs Rebase
These are two ways to integrate changes from one branch into another. Understanding the difference is crucial.Merge
What is Merge?
What is Merge?
Merge combines two branches by creating a new “merge commit” that has two parents.Visual:Characteristics:
- Preserves complete history
- Creates a merge commit
- Non-destructive (doesn’t rewrite history)
- Can create a “messy” history with lots of branches
Rebase
What is Rebase?
What is Rebase?
Rebase moves your branch’s commits to the tip of another branch, rewriting history to be linear.Visual:Characteristics:
- Creates a clean, linear history
- Rewrites commit history (new commit IDs)
- Makes it look like you branched from the latest code
- Preferred for feature branches before merging
When to Use Each
Use Merge When
- Merging feature branches into
main - You want to preserve exact history
- Working on shared branches
Use Rebase When
- Updating your feature branch with latest
main - You want clean, linear history
- Working on your own feature branch
Understanding Merge Conflicts
What is a Merge Conflict?
A merge conflict happens when Git can’t automatically combine changes because two people edited the same lines of code differently.Conflicts are normal and not a sign you did something wrong—they’re just Git asking you to make a decision.
Conflict Markers Explained
When a conflict occurs, Git marks the conflicting sections in your files:<<<<<<< HEAD
Everything between this and
======= is your current code (what’s in your branch right now)Resolving Conflicts
Decide what to keep
You have three options:
- Keep your version
- Keep their version
- Combine both (manually edit)
Common Git Terms
HEAD
HEAD
A pointer to the current branch and commit you’re on. Think of it as “you are here” marker.
Origin
Origin
The default name for the remote repository (usually on GitHub/GitLab).
Remote
Remote
A version of your repository hosted on a server (like GitHub). You can have multiple remotes.
Working Directory
Working Directory
The actual files on your computer. This is where you edit code.
Staging Area (Index)
Staging Area (Index)
A intermediate area where you prepare files before committing. Files go here when you
git add.Fast-forward
Fast-forward
A type of merge where Git can simply move the branch pointer forward (no merge commit needed).
Squash
Squash
Combining multiple commits into one. Often used when merging feature branches to keep
main clean.Cherry-pick
Cherry-pick
Copying a specific commit from one branch to another.
Stash
Stash
Temporarily saving uncommitted changes so you can switch branches.
Detached HEAD
Detached HEAD
When HEAD points directly to a commit instead of a branch. Usually happens when checking out a specific commit.
Git Workflow Diagram
Common Scenarios
Scenario 1: Update Your Feature Branch
You’re working on
feature/my-feature and main has new commits. You want the latest changes.Scenario 2: Undo Last Commit (Not Pushed)
Scenario 3: Save Work in Progress
Scenario 4: See What Changed
Quick Reference
Check Status
View History
Create Branch
Switch Branch
Delete Branch
Discard Changes
Next Steps
Now that you understand Git fundamentals, learn our team workflows:Git Workflow Guide
Learn our branching strategy and merge practices
Commit Message Guide
Follow our commit message conventions
Understanding these fundamentals will make you confident with Git and help you collaborate effectively.