Version Control

Git & Version Control: The Time Machine for Code

Updated June 2026
Git and GitHub Development Concept
Git is the standard software developers use to save and share project code checkpoints worldwide.

Hello, future software creators! Today we are learning about a developer superpower: Git. Without Git, writing code with a team of developers would feel like trying to write a single essay together by emailing draft files back and forth. It would be absolute chaos!

Let's discover what Git is, why everyone uses it, and how it acts as a magical time machine for your code.

The Checkpoint Analogy: Saving Your Code Game

Imagine you are playing a difficult adventure video game. Before entering a dark castle to fight a giant monster, what do you do? You walk up to a save-point and save your game progress! If the monster beats you, you don't start the entire game from level 1. You just restart from your last saved checkpoint.

Writing code is exactly like that. When you write a new feature—for example, adding a dark-mode switch to a website—you might accidentally write a bug that crashes the entire homepage. If you didn't save your progress, you'd have to press undo 500 times or rewrite the whole site.

Git is the ultimate checkpoint system. It monitors your project folder and lets you freeze the code at any point in time. We call these checkpoints Commits. If you break the website, you can tell Git to instantly rewind the folder back to yesterday's commit, and everything is fixed!

The Google Docs Metaphor: Working Together

If you and your classmates write a school report together in a Google Doc, you can both type at the same time. But what if two developers are editing a complex server script? If they work in the same file, they could overwrite each other's code and cause crashes.

Git solves this by giving every developer their own private playground branch. You duplicate the code into a separate Branch, make your changes, and once you test it, you merge it back into the main branch. If two changes clash, Git points it out (a Merge Conflict) and asks you to choose which line is the correct one.

Core Git Terms Explained Simply

Repository (Repo)

This is just a project folder on your computer that has Git enabled inside it. It holds all your code and the history logs.

Commit

A saved snapshot of your code at a specific moment. Each commit gets a unique ID and a short message describing the changes.

Branch

A parallel version of your repository. The default main branch is where the live code lives; custom branches are for safe testing.

GitHub

A cloud library where developers upload their repositories so others can download, collaborate, and review the code online.

11 Everyday Git Commands Every Engineer Needs

To use Git, you open your terminal console inside your project folder and run commands. Here is a complete cheat sheet of the 11 commands you will use daily:

Purpose Git Command Real-World Metaphor & Example
Start Tracking git init Initializes Git inside a folder. Like installing a black box flight recorder in a plane.
Example: git init (Run once at the start of a project).
Download Project git clone <url> Downloads a copy of an existing cloud repository from GitHub to your computer.
Example: git clone https://github.com/user/my-app.git
Check Status git status Asks Git: "What files have I modified since the last checkpoint?"
Example: git status (Shows modified files in red or green).
Stage Changes git add <file> Packs the modified files into a shipping container, ready to be locked.
Example: git add index.html (Or git add . to stage everything).
Create Checkpoint git commit -m "msg" Locks the shipping container and saves it as a checkpoint with a descriptive message.
Example: git commit -m "Feat: Add dark mode toggle button"
Upload to Cloud git push Uploads your local checkpoints from your computer to the repository on GitHub.
Example: git push origin main
Download Updates git pull Fetches and merges the latest updates that other developers pushed to GitHub.
Example: git pull
List/Create Branches git branch Creates a new branch path or lists the existing branches in your repository.
Example: git branch feature-login-page
Switch Workspace git checkout <branch> Jumps your workspace folder from one branch to another.
Example: git checkout feature-login-page
Merge Code git merge <branch> Combines and blends the code checkpoints of another branch into your current branch.
Example: git merge feature-login-page (Run from the main branch).
View History git log Outputs a scrollable history log of every single commit checkpoint created in the project.
Example: git log --oneline (Shows short commit list).

Real-World Scenario: Safe Checkout Page Updates

Suppose you are working on the checkout page of a massive shopping website. The marketing team wants a new discount code field, but the checkout page is incredibly sensitive. If you break it, checkout transactions stop instantly and the company loses crores of rupees!

To implement this safely:

  1. You switch to the master branch and download latest updates: git checkout main; git pull.
  2. You create a secure test branch: git checkout -b feature-discount-code.
  3. You write code, test it locally, stage, and save your checkpoints: git add .; git commit -m "Feat: Add UPI discount code logic".
  4. You push the branch online to GitHub: git push origin feature-discount-code.
  5. You open a Pull Request on GitHub. The senior engineer reviews your changes, runs automated tests, approves it, and clicks Merge. Your code is safely blended into the main site!

Pro-Tip for Git Commits

Always write clean commit messages! Instead of typing messages like git commit -m "stuff done", write clear descriptions like git commit -m "Fix: Resolve card page button layout padding". This makes debugging much easier when you use the history logs later!

Next Steps on Your DevOps Journey

Now that you know how to save and cooperate on your codebase using Git, you are ready to packaging your application files alongside all of their runtime systems using Docker containers!

Test Your Knowledge

Answer these 25 questions to check your understanding of this module. Click on an option to reveal the correct answer instantly.

Question 1 of 25
Which command initializes a new Git repository?
A. git start
B. git init
C. git create
D. git new
Explanation: git init creates a new .git directory.
Question 2 of 25
How do you check the status of files in the working directory?
A. git info
B. git log
C. git status
D. git check
Explanation: git status shows working tree status.
Question 3 of 25
Which command stages changes?
A. git add
B. git stage
C. git commit
D. git push
Explanation: git add moves changes to the staging area.
Question 4 of 25
How do you commit staged changes?
A. git save
B. git commit
C. git push
D. git store
Explanation: git commit records changes to the repository.
Question 5 of 25
Which command lists the commit history?
A. git history
B. git log
C. git past
D. git list
Explanation: git log shows the commit logs.
Question 6 of 25
How do you create a new branch?
A. git checkout -b name
B. git branch -n name
C. git new name
D. git create name
Explanation: git checkout -b creates and switches to a new branch.
Question 7 of 25
Which command merges a branch into the current branch?
A. git join
B. git merge
C. git combine
D. git fuse
Explanation: git merge joins two or more development histories.
Question 8 of 25
What is the command to clone a remote repository?
A. git copy
B. git clone
C. git download
D. git pull
Explanation: git clone copies a repository into a new directory.
Question 9 of 25
How do you fetch and merge changes from the remote?
A. git fetch
B. git pull
C. git push
D. git sync
Explanation: git pull performs a fetch followed by a merge.
Question 10 of 25
What is "HEAD" in Git?
A. The first commit
B. The main branch
C. A pointer to the current commit
D. The remote repository
Explanation: HEAD is a pointer to the current snapshot you are working on.
Question 11 of 25
Which command temporarily saves dirty work without committing?
A. git stash
B. git hide
C. git store
D. git pause
Explanation: git stash saves uncommitted changes for later use.
Question 12 of 25
How do you unstage a file?
A. git remove
B. git reset
C. git delete
D. git undo
Explanation: git reset HEAD unstages a file.
Question 13 of 25
Which command shows the difference between working dir and staging?
A. git show
B. git diff
C. git compare
D. git status
Explanation: git diff shows changes between commits, commit and working tree, etc.
Question 14 of 25
How do you discard local changes to a specific file?
A. git checkout -- file
B. git remove file
C. git drop file
D. git clean file
Explanation: git checkout -- restores the file from the last commit/staging.
Question 15 of 25
What command handles remote URLs?
A. git url
B. git remote
C. git origin
D. git connect
Explanation: git remote manage set of tracked repositories.
Question 16 of 25
What is a "fork"?
A. A new branch
B. A copy of a repo in your own account
C. A git error
D. A merge conflict
Explanation: A fork is a personal copy of another users repository.
Question 17 of 25
Which file tells Git to ignore specific files?
A. .gitconfig
B. .gitignore
C. .gitkeep
D. .githide
Explanation: .gitignore specifies intentionally untracked files to ignore.
Question 18 of 25
How do you view the details of a specific commit?
A. git show
B. git view
C. git log
D. git inspect
Explanation: git show displays details of a commit object.
Question 19 of 25
What does "git rebase" do?
A. Merges two branches
B. Deletes a branch
C. Moves the base of a branch to another commit
D. Creates a backup
Explanation: Rebase reapplies commits on top of another base tip.
Question 20 of 25
How do you delete a local branch?
A. git branch -d
B. git remove -b
C. git delete
D. git erase
Explanation: git branch -d deletes a branch.
Question 21 of 25
Which command tags a specific commit?
A. git label
B. git tag
C. git mark
D. git sign
Explanation: git tag creates a tag object.
Question 22 of 25
How do you push tags to remote?
A. git push --tags
B. git send tags
C. git upload --tags
D. git sync tags
Explanation: git push --tags sends all local tags to the remote.
Question 23 of 25
What is "git blame" used for?
A. Finding errors
B. Showing who last modified each line
C. Deleting bad code
D. Merging conflicts
Explanation: git blame shows what revision and author last modified each line of a file.
Question 24 of 25
What is "origin" in Git?
A. The master branch
B. The local folder
C. The default alias for the remote repository
D. The first commit
Explanation: Origin is the default shorthand name for the remote repository.
Question 25 of 25
How do you revert a commit that has been pushed?
A. git undo
B. git revert
C. git remove
D. git back
Explanation: git revert creates a new commit that undoes the changes of a previous commit.