TRACK YOUR
CODE

// The world's most popular version control system.

GIT IS THE BACKBONE OF COLLABORATION.

Git tracks every change to your code, allowing you to revert mistakes, branch experiments, and collaborate with others seamlessly. It's the standard for version control in software development.

WHY GIT?

Git is distributed—every developer has a full copy of the repository. It works offline, handles large projects efficiently, and enables powerful branching strategies for teams of any size.

OWN YOUR HISTORY.

Every commit is a snapshot. Every branch is a parallel timeline. Git gives you complete control over your project's evolution—no lock-in, no data loss, just pure version control.

BEGIN YOUR JOURNEY →

// The Path to Mastery

12 lessons. Complete Git control.

LESSON 01

Introduction to Git

Understand version control and Git basics

Beginner
LESSON 02

Creating Repositories

Initialize repos and make first commits

Beginner
LESSON 03

Basic Commands

Add, commit, status, and log fundamentals

Beginner
LESSON 04

Branching & Merging

Work with branches and merge changes

Beginner
LESSON 05

Remote Repositories

Connect to GitHub, push and pull code

Beginner
LESSON 06

Undoing Changes

Revert, reset, and fix mistakes safely

Intermediate
LESSON 07

Stashing Changes

Temporarily save work without committing

Intermediate
LESSON 08

Tagging Releases

Mark versions and important milestones

Intermediate
LESSON 09

Rebasing

Clean up history and integrate changes cleanly

Intermediate
LESSON 10

GitHub & Collaboration

Fork, pull requests, and team workflows.

Intermediate
LESSON 11

Advanced Git Commands

Cherry-pick, bisect, and powerful features.

Advanced
LESSON 12

Git Best Practices

Commit conventions, branching strategies, workflows.

Advanced

// Why Git

Git was created by Linus Torvalds in 2005 to manage the Linux kernel project. Today, it's used by millions of developers—from individual programmers to massive corporations.

Git's distributed nature means no single point of failure. You can work offline, create branches for experiments, merge when ready, and share your work with anyone through platforms like GitHub, GitLab, and Bitbucket.

Understanding Git is essential for modern development. It's not just about version control—it's about collaboration, code review, automation, and DevOps practices.

The future of collaboration is Git. Own it.

// Tools & References

📖 Pro Git Book

Free online book

git-scm.com/book

🐙 GitHub

Code hosting platform

github.com

🔧 GitLab

DevOps platform

gitlab.com

📱 GitKraken

Git GUI client

gitkraken.com

🖥️ GitHub CLI

Command line tool

cli.github.com

📚 Oh My Git

Interactive Git learning

ohmygit.org

// Introduction to Git

×

What is Git?

Git is a distributed version control system that tracks changes in your code. It was created by Linus Torvalds in 2005 and has become the standard for version control worldwide.

Why Git?

  • Distributed: Every developer has a full repository copy
  • Fast: Designed for speed and efficiency
  • Branching: Create parallel versions of your code easily
  • Open Source: Free and maintained by the community
  • Industry Standard: Used by virtually every tech company
GIT'S PHILOSOPHY: Git thinks of its data more like a stream of snapshots. Every time you commit, Git takes a picture of what your files look like and stores a reference to that snapshot.

Installing Git

$ git --version git version 2.43.0

Configuring Git

$ git config --global user.name "Your Name" $ git config --global user.email "you@example.com" $ git config --global init.defaultBranch main

The Three States

Git has three main states for your files:

  • Modified: Changed but not marked for commit
  • Staged: Marked as ready to be committed
  • Committed: Safely stored in your database

Quiz

1. Git was created by _____ in 2005.

Hint: Linux creator

2. Git is a _____ version control system.

Hint: Not centralized

3. Files marked for commit are in the _____ state.

Hint: Ready to commit

4. Use _____ to set your identity.

Hint: Configuration command

5. Committed files are stored in the _____.

Hint: Repository

6. The three states are modified, staged, and _____.

Hint: Final state

7. git --version shows the _____.

Hint: Release number

8. Git tracks _____ in your code.

Hint: What files contain

Show Answers

Answers

  1. Linus Torvalds
  2. distributed
  3. staged
  4. git config
  5. database
  6. committed
  7. version
  8. changes

// Creating Repositories

×

What is a Repository?

A Git repository is a directory that contains your project files and the entire history of changes. It's the core concept in Git.

Initializing a Repository

$ mkdir myproject $ cd myproject $ git init Initialized empty Git repository in /home/user/myproject/.git/

Cloning an Existing Repository

Use git clone to get a copy of an existing repository.

$ git clone https://github.com/user/repo.git Cloning into 'repo'... remote: Enumerating objects: 100, done. Receiving objects: 100% (50/50), done.

The .git Directory

When you initialize or clone a repository, Git creates a hidden .git directory. This contains all the metadata and object database for your project.

$ ls -la total 20 drwxr-xr-x 4 user user 4096 Feb 23 12:00 . drwxr-xr-x 1 user user 4096 Feb 23 12:00 .. drwxr-xr-x 3 user user 4096 Feb 23 12:00 .git

Checking Repository Status

$ git status On branch main No commits yet nothing to commit (create/copy files and use "git add")

Quiz

1. Use _____ to initialize a new repository.

Hint: Initialize command

2. Use git _____ to copy an existing repository.

Hint: Get a copy

3. The .git directory contains the _____.

Hint: Object storage

4. git status shows the current _____.

Hint: Branch and changes

5. A repository contains project _____ and history.

Hint: Your code

6. git clone creates a _____ directory.

Hint: From remote

7. No commits yet means the repository is _____.

Hint: No snapshots

8. Initializing creates a hidden ._____ directory.

Hint: Git folder

Show Answers

Answers

  1. git init
  2. clone
  3. database
  4. state
  5. files
  6. new
  7. empty
  8. git

// Basic Commands

×

The Git Workflow

The basic Git workflow involves: modifying files, staging changes, and committing them.

Checking Status

$ git status On branch main Untracked files: (use "git add ..." to include in what will be committed) README.md

Staging Files

Use git add to stage files for commit.

$ git add README.md $ git add . # Add all files

Committing Changes

$ git commit -m "Add README file" [main (root-commit) 1a2b3c4] Add README file 1 file changed, 5 insertions(+) create mode 100644 README.md

Viewing History

$ git log commit 1a2b3c4d5e6f7g8h9i0j (HEAD -> main) Author: Your Name Date: Mon Feb 23 12:00:00 2026 Add README file

Viewing Differences

$ git diff # Show unstaged changes $ git diff --staged # Show staged changes

Quiz

1. Use git _____ to stage files.

Hint: Prepare for commit

2. Use git _____ to save changes.

Hint: Snapshot state

3. git log shows _____.

Hint: Past commits

4. git diff shows _____.

Hint: What changed

5. git add . stages _____ files.

Hint: Every file

6. A commit message uses the _____ flag.

Hint: Message flag

7. git diff --staged shows _____ changes.

Hint: Ready to commit

8. Each commit has a unique _____.

Hint: Commit ID

Show Answers

Answers

  1. add
  2. commit
  3. history
  4. changes
  5. all
  6. -m
  7. staged
  8. hash

// Branching & Merging

×

What is a Branch?

A branch is a parallel version of your repository. It allows you to work on features without affecting the main codebase.

Creating Branches

$ git branch feature-login # Create a new branch $ git checkout -b feature-signup # Create and switch in one command

Switching Branches

$ git checkout main # Switch to main branch $ git switch main # New syntax (Git 2.23+)

Listing Branches

$ git branch feature-login * main $ git branch -a # Show all branches including remote

Merging Branches

$ git checkout main $ git merge feature-login Merge made by the 'recursive' strategy. README.md | 2 ++ 1 file changed, 2 insertions(+)

Deleting Branches

$ git branch -d feature-login # Delete local branch $ git push origin --delete feature-login # Delete remote branch

Quiz

1. Use git _____ to create a branch.

Hint: Create command

2. Use git _____ to switch branches.

Hint: Switch command

3. git checkout -b creates and _____.

Hint: Both actions

4. Use git _____ to combine branches.

Hint: Join together

5. git branch -d _____ a branch.

Hint: Removes

6. * in git branch output shows _____.

Hint: Active branch

7. Branches allow _____ development.

Hint: Simultaneous

8. git push origin --delete removes _____ branch.

Hint: On server

Show Answers

Answers

  1. branch
  2. checkout
  3. switches
  4. merge
  5. deletes
  6. current
  7. parallel
  8. remote

// Remote Repositories

×

What are Remotes?

Remotes are versions of your repository hosted on the internet or network. They allow collaboration with others.

Viewing Remotes

$ git remote -v origin https://github.com/user/repo.git (fetch) origin https://github.com/user/repo.git (push)

Adding Remotes

$ git remote add upstream https://github.com/original/repo.git

Fetching Changes

Fetch downloads changes from remote without merging them.

$ git fetch origin remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done.

Pushing Changes

Push uploads your commits to the remote repository.

$ git push origin main Enumerating objects: 5, done. To https://github.com/user/repo.git a1b2c3d..e4f5g6h main -> main

Pulling Changes

Pull fetches and merges changes in one command.

$ git pull origin main From https://github.com/user/repo * branch main -> FETCH_HEAD Updating a1b2c3d..e4f5g6h Fast-forward README.md | 2 ++ 1 file changed, 2 insertions(+)

Quiz

1. Use git _____ to view remotes.

Hint: Remote command

2. origin is the default _____ name.

Hint: Primary remote

3. git _____ downloads without merging.

Hint: Get changes

4. git _____ uploads commits.

Hint: Send to remote

5. git _____ fetches and merges.

Hint: Get and combine

6. git remote add _____ creates a remote.

Hint: Label for URL

7. git push -u sets the _____ branch.

Hint: Default tracking

8. git fetch updates _____ commits.

Hint: Not working files

Show Answers

Answers

  1. remote
  2. remote
  3. fetch
  4. push
  5. pull
  6. name
  7. upstream
  8. local

// Undoing Changes

×

Unstaging Files

Use git reset to unstage files.

$ git reset README.md # Unstage a specific file $ git reset # Unstage all files

Discarding Local Changes

$ git checkout -- README.md # Discard changes to a file $ git restore README.md # New syntax (Git 2.23+)

Amending Commits

Change the last commit (before pushing!).

$ git commit --amend -m "New message" # Change commit message $ git commit --amend --no-edit # Add staged changes to last commit

Reverting Commits

Create a new commit that undoes previous changes.

$ git revert abc1234 # Revert specific commit $ git revert HEAD~3..HEAD # Revert last 3 commits

Resetting to a Previous State

$ git reset --soft HEAD~1 # Move HEAD back, keep changes staged $ git reset --mixed HEAD~1 # Default - keep changes unstaged $ git reset --hard HEAD~1 # DANGER: Discard all changes

Quiz

1. git _____ unstages files.

Hint: Remove from staging

2. git checkout -- file _____ changes.

Hint: Throws away

3. git commit --_____ modifies the last commit.

Hint: Fix mistakes

4. git _____ creates a new undo commit.

Hint: Safe undo

5. git reset --_____ is dangerous.

Hint: Loses all data

6. Use git _____ to restore files.

Hint: New command

7. --soft keeps changes _____.

Hint: In staging area

8. Never amend commits that have been _____.

Hint: Shared with others

Show Answers

Answers

  1. reset
  2. discards
  3. amend
  4. revert
  5. hard
  6. restore
  7. staged
  8. pushed

// Stashing Changes

×

What is Stashing?

Stashing saves your uncommitted changes temporarily, so you can switch branches or pull updates.

Creating a Stash

$ git stash Saved working directory and index state WIP on main: 1a2b3c4 Add feature $ git stash push -m "Work in progress on login" # With a message

Viewing Stashes

$ git stash list stash@{0}: WIP on main: 1a2b3c4 Add feature stash@{1}: On main: Work on header

Applying Stashes

$ git stash pop # Apply and remove latest stash $ git stash apply # Apply without removing $ git stash apply stash@{1} # Apply specific stash

Dropping Stashes

$ git stash drop # Remove latest stash $ git stash drop stash@{0} # Remove specific stash $ git stash clear # Remove all stashes

Quiz

1. git _____ saves changes temporarily.

Hint: Save for later

2. git stash _____ applies and removes.

Hint: Apply and delete

3. git stash _____ applies without removing.

Hint: Keep stash

4. git stash list shows all _____.

Hint: Saved changes

5. git stash _____ removes all stashes.

Hint: Delete everything

6. Use stash when you need to _____ branches.

Hint: Change branches

7. git stash -m adds a _____.

Hint: Description

8. stash@{0} is the _____ stash.

Hint: Most recent

Show Answers

Answers

  1. stash
  2. pop
  3. apply
  4. stashes
  5. clear
  6. switch
  7. message
  8. latest

// Tagging Releases

×

What are Tags?

Tags mark specific points in Git history, commonly used for releases (v1.0, v2.0, etc.).

Creating Annotated Tags

$ git tag -a v1.0.0 -m "Release version 1.0.0" # Create annotated tag

Creating Lightweight Tags

$ git tag v1.0.0 # Lightweight tag

Listing Tags

$ git tag v1.0.0 v1.1.0 v2.0.0 $ git tag -l "v1.*" # List tags matching pattern

Tagging Past Commits

$ git tag -a v0.9.0 abc1234 -m "Initial release" # Tag a past commit

Pushing Tags

$ git push origin v1.0.0 # Push specific tag $ git push origin --tags # Push all tags

Deleting Tags

$ git tag -d v1.0.0 # Delete local tag $ git push origin --delete v1.0.0 # Delete remote tag

Quiz

1. Tags mark specific _____ in history.

Hint: Versions

2. git tag -a creates an _____ tag.

Hint: With message

3. git tag without flags creates _____ tag.

Hint: Simple

4. Use -m for the tag _____.

Hint: Description

5. git push origin _____ pushes a tag.

Hint: Specific tag

6. git push origin --_____ pushes all tags.

Hint: All at once

7. git tag -d deletes _____ tag.

Hint: On your machine

8. Tags are commonly used for _____.

Hint: Version marks

Show Answers

Answers

  1. points
  2. annotated
  3. lightweight
  4. message
  5. tagname
  6. tags
  7. local
  8. releases

// Rebasing

×

What is Rebasing?

Rebasing moves or combines a sequence of commits to a new base commit. It creates a cleaner history.

Golden Rule: Never rebase commits that have been pushed to a shared repository!

Basic Rebase

$ git checkout feature $ git rebase main # Move feature branch onto main

Interactive Rebase

Edit, squash, or reorder commits.

$ git rebase -i HEAD~3 # Edit last 3 commits

Rebase Commands

  • pick: Use the commit
  • reword: Change the commit message
  • squash: Combine with previous commit
  • drop: Remove the commit

Rebase vs Merge

  • Merge: Creates a merge commit, preserves exact history
  • Rebase: Creates linear history, rewrites commits

Quiz

1. git _____ moves commits to new base.

Hint: Change base

2. Never rebase _____ commits.

Hint: Shared history

3. git rebase -i is _____ rebase.

Hint: With choices

4. squash combines commits with _____.

Hint: The one before

5. reword changes the _____ message.

Hint: Commit text

6. Rebase creates _____ history.

Hint: Straight line

7. drop in rebase means _____ commit.

Hint: Delete

8. Merge preserves exact _____..

Hint: All commits

Show Answers

Answers

  1. rebase
  2. pushed
  3. interactive
  4. previous
  5. commit
  6. linear
  7. remove
  8. history

// GitHub & Collaboration

×

Forking Workflow

Fork → Clone → Branch → Commit → Push → Pull Request

Creating a Fork

Click the "Fork" button on GitHub to create your own copy.

Cloning Your Fork

$ git clone https://github.com/your-user/repo.git $ git remote add upstream https://github.com/original/repo.git

Keeping Fork Updated

$ git fetch upstream $ git checkout main $ git merge upstream/main

Creating Pull Requests

  1. Push your branch to your fork
  2. Click "New Pull Request" on GitHub
  3. Select base and compare branches
  4. Add description and create PR

Syncing Fork from Web UI

GitHub's "Sync fork" button updates your fork with one click.

Quiz

1. A _____ creates your copy of a repo.

Hint: GitHub feature

2. git remote add _____ points to original.

Hint: Main repo

3. git fetch _____ gets latest changes.

Hint: From original

4. Pull requests are created on _____.

Hint: Web platform

5. Sync fork updates from _____ repository.

Hint: Main project

6. git clone creates a local _____.

Hint: On your machine

7. Fork workflow: Fork → Clone → Branch → _____ → Push → PR.

Hint: Save changes

8. PR stands for Pull _____.

Hint: Ask to merge

Show Answers

Answers

  1. fork
  2. upstream
  3. upstream
  4. GitHub
  5. original
  6. copy
  7. commit
  8. Request

// Advanced Git Commands

×

Cherry-Picking

Apply specific commits from one branch to another.

$ git cherry-pick abc1234 # Apply commit to current branch

BISect

Binary search to find the commit that introduced a bug.

$ git bisect start $ git bisect bad # Current version is broken $ git bisect good v1.0.0 # This version works # Git checks out middle commit # Test and run: git bisect good or bad # When found: git bisect reset

Worktrees

Work on multiple branches simultaneously.

$ git worktree add ../feature-branch feature # Create new worktree $ git worktree list # List worktrees

Reflog

View all reference updates (your safety net!).

$ git reflog abc1234 HEAD@{0}: commit: Add feature def5678 HEAD@{1}: checkout: moving to main $ git checkout HEAD@{1} # Recover lost commit

Clean

Remove untracked files.

$ git clean -n # Preview what would be deleted $ git clean -fd # Actually delete files and directories

Quiz

1. git _____ applies specific commits.

Hint: Select commits

2. git _____ finds bug commits.

Hint: Binary search

3. git worktree allows _____ branches.

Hint: Simultaneous

4. git _____ is your safety net.

Hint: Reference log

5. git clean removes _____ files.

Hint: Not in Git

6. git bisect good/bad does binary _____.

Hint: Find bug

7. HEAD@{0} is the _____ position.

Hint: Latest

8. git clean -n does a _____.

Hint: Dry run

Show Answers

Answers

  1. cherry-pick
  2. bisect
  3. multiple
  4. reflog
  5. untracked
  6. search
  7. current
  8. preview

// Git Best Practices

×

Writing Good Commit Messages

  • First line: 50 characters or less
  • Use imperative mood ("Add feature" not "Added")
  • Blank line, then detailed explanation
  • Reference issues/tickets
Add user login feature Implement JWT authentication with OAuth2 support. Validate user credentials against database. Store refresh tokens securely in httpOnly cookies. Closes #123

Branching Strategies

  • Git Flow: main, develop, feature/, release/, hotfix/
  • GitHub Flow: main with feature branches
  • Trunk-Based: Short-lived branches

.gitignore

Exclude files from version control.

# Dependencies node_modules/ # Build outputs dist/ build/ # Secrets .env *.pem # OS files .DS_Store Thumbs.db

Aliases

Create shortcuts for common commands.

$ git config --global alias.st status $ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.lg "log --oneline --graph --all"

Daily Git Habits

  • Pull before starting work
  • Commit often with clear messages
  • Push at end of day
  • Review before pushing
  • Use branches for features

Quiz

1. Commit messages should use _____ mood.

Hint: Commands

2. First line of commit should be under _____ chars.

Hint: Short

3. node_modules should be in _____.

Hint: Excluded files

4. git config --global alias.st _____

Hint: Shortcut

5. Always _____ before starting work.

Hint: Get latest

6. Git Flow uses _____ branch for releases.

Hint: Production

7. Use branches for _____ development.

Hint: New functionality

8. Review changes before _____.

Hint: Uploading

Show Answers

Answers

  1. imperative
  2. 50
  3. .gitignore
  4. status
  5. pull
  6. main
  7. feature
  8. pushing