Skip to main content
Start here if you’re new to Git or need a refresher on core concepts like rebase, merge, conflicts, and branching.
This guide explains the fundamental Git concepts you’ll encounter in our workflow.

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).
/Users/aman/Desktop/Handa Uncle/backend/ This is a repository

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
git add .
git commit -m "feat(api): add user search endpoint"
Think of commits as save points in a video game—you can always go back to any commit.

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
git checkout -b feature/my-new-feature

Key Operations Explained

Clone

Cloning downloads a repository from GitHub/GitLab to your local machine.
git clone https://github.com/username/repo.git

Pull

Pulling downloads the latest changes from the remote repository to your local branch.
git pull origin main
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).
git push origin feature/my-feature

Add (Staging)

Adding files puts them in the “staging area”—marking them to be included in the next commit.
git add file1.ts file2.ts    # stage specific files
git add .                     # stage all changed files

Merge vs Rebase

These are two ways to integrate changes from one branch into another. Understanding the difference is crucial.

Merge

Merge combines two branches by creating a new “merge commit” that has two parents.Visual:
main:     A---B---C---D
                     /
feature:        E---F

After merge:
main:     A---B---C---D---G (merge commit)
                     /   /
feature:        E---F---
Characteristics:
  • Preserves complete history
  • Creates a merge commit
  • Non-destructive (doesn’t rewrite history)
  • Can create a “messy” history with lots of branches
git checkout main
git merge feature/my-feature

Rebase

Rebase moves your branch’s commits to the tip of another branch, rewriting history to be linear.Visual:
main:     A---B---C---D
               \
feature:        E---F

After rebase:
main:     A---B---C---D
                       \
feature:                E'---F' (new commits)
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
git checkout feature/my-feature
git rebase main
Never rebase commits that have been pushed to a shared branch that others are working on. Only rebase your own feature branches.

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 (your current branch)
const apiUrl = "http://localhost:8080";
=======
const apiUrl = "https://api.production.com";
>>>>>>> feature/update-api-url (incoming changes)
Breaking it down:
1

<<<<<<< HEAD

Everything between this and ======= is your current code (what’s in your branch right now)
2

=======

This line separates the two conflicting versions
3

>>>>>>> branch-name

Everything between ======= and this is the incoming code (what you’re trying to merge in)

Resolving Conflicts

1

Open the conflicting file

Your editor will show the conflict markers
2

Decide what to keep

You have three options:
  • Keep your version
  • Keep their version
  • Combine both (manually edit)
3

Remove conflict markers

Delete the <<<<<<<, =======, and >>>>>>> lines
4

Save and stage the file

git add conflicted-file.ts
5

Continue the merge/rebase

git rebase --continue  # if rebasing
# or
git commit             # if merging
// Before (with conflict)
<<<<<<< HEAD
const apiUrl = "http://localhost:8080";
=======
const apiUrl = "https://api.production.com";
>>>>>>> feature/update-api-url

// After (resolved - keep production URL)
const apiUrl = "https://api.production.com";

Common Git Terms

A pointer to the current branch and commit you’re on. Think of it as “you are here” marker.
HEAD main commit abc123
The default name for the remote repository (usually on GitHub/GitLab).
origin https://github.com/username/repo.git
A version of your repository hosted on a server (like GitHub). You can have multiple remotes.
The actual files on your computer. This is where you edit code.
A intermediate area where you prepare files before committing. Files go here when you git add.
A type of merge where Git can simply move the branch pointer forward (no merge commit needed).
main:     A---B
               \
feature:        C---D

After fast-forward merge:
main:     A---B---C---D (no merge commit)
Combining multiple commits into one. Often used when merging feature branches to keep main clean.
feature: A---B---C---D

After squash merge to main:
main: X (one commit containing all changes from A, B, C, D)
Copying a specific commit from one branch to another.
git cherry-pick abc123  # apply commit abc123 to current branch
Temporarily saving uncommitted changes so you can switch branches.
git stash        # save changes
git stash pop    # restore changes
When HEAD points directly to a commit instead of a branch. Usually happens when checking out a specific commit.
git checkout abc123  # creates detached HEAD state

Git Workflow Diagram

1

Edit files

Make changes in your working directory
2

Stage changes

Use git add to stage files
3

Commit

Use git commit to save snapshot
4

Push

Use git push to upload to remote

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.
git checkout feature/my-feature
git fetch origin
git rebase origin/main

Scenario 2: Undo Last Commit (Not Pushed)

git reset --soft HEAD~1
--hard permanently deletes your changes. Be careful!

Scenario 3: Save Work in Progress

git stash save "work in progress on login feature"

# Switch branches, do other work...

# Come back and restore
git stash pop

Scenario 4: See What Changed

git diff

# View changes in a specific file
git diff src/index.ts

# View staged changes
git diff --staged

Quick Reference

Check Status

git status
See what files are changed, staged, etc.

View History

git log
git log --oneline
See commit history

Create Branch

git checkout -b feature/new
Create and switch to new branch

Switch Branch

git checkout main
Switch to existing branch

Delete Branch

git branch -d feature/old
Delete local branch

Discard Changes

git checkout -- file.ts
Undo uncommitted changes

Next Steps

Now that you understand Git fundamentals, learn our team workflows:
Understanding these fundamentals will make you confident with Git and help you collaborate effectively.