Use Sophia to knock out your gen-ed requirements quickly and affordably. Learn more
×

Introduction to Git & Version Control

Author: Sophia

what's covered
In this lesson, you will learn about version control systems and how they help developers track changes to their code over time. You will explore how Git, a popular distributed version control system, enables both individual developers and teams to manage their projects effectively. Specifically, this lesson will cover the following:

Table of Contents

1. Understanding Version Control

before you start
In earlier lessons, you accessed GitHub and the development environment used in this course. In this tutorial, you will step back from the tools and focus on understanding how version control works and why it is essential in web development. You will learn how Git tracks changes and how platforms like GitHub support collaboration, without performing any hands-on tasks yet.

Before diving into specific tools, it helps to understand why version control exists in the first place. Every developer, whether working alone or on a team, faces common challenges when managing code files over time.

1a. The Problem Version Control Solves

Imagine you are working on a website project. You have your HTML, CSS, and JavaScript files organized in a folder. As you make changes, you might run into several problems:

  • You make a change that breaks something, and you cannot remember exactly what the code looked like before.
  • You want to try an experimental feature but are afraid of ruining your working code.
  • You accidentally delete an important file or overwrite it with the wrong content.
  • You need to work on the same files as another person, and your changes conflict with each other.
Without a system to manage these situations, developers often resort to manual solutions like creating copies of their project folder with names like “website_v1,” “website_v2,” “website_final,” and “website_final_REALLY_FINAL.” This approach quickly becomes confusing and unreliable.

recall
Think back to your experience saving documents for school or work. Have you ever wished you could go back to an earlier version of something you wrote? Version control provides exactly that capability for code.

1b. What Is Version Control?

Version control is a system that records changes to files over time so you can recall specific versions later. Think of it as a detailed save history for your project that remembers not just the current state of your files but every change you have ever made.

A helpful analogy is to think of version control like the “Track Changes” feature in word processors but far more powerful. While Track Changes shows edits in a single document, version control tracks the complete history of every file in your entire project.

With version control, you can:

  • See exactly what changed in your code, when it changed, and who changed it
  • Restore your project to any previous state
  • Work on new features without risking your stable code
  • Merge changes made by multiple people into a single project
  • Maintain a complete backup of your project history
key concept
Version control systems create a timeline of your project. Each point on that timeline represents a snapshot of all your files at a specific moment. You can move forward, backward, or even create alternate timelines to experiment safely.

term to know
Version Control
A system that records changes to files over time, allowing developers to track history, restore previous versions, and coordinate work among multiple people.


2. Introduction to Git

While many version control systems exist, Git has become the most widely used tool for tracking changes in software projects. Git is a distributed version control system that records snapshots of files over time, allowing developers to see what changed, restore earlier versions, and manage multiple lines of development safely.

Git is designed to support both individual work and collaboration. It tracks changes locally on a developer’s computer while also supporting shared workflows through remote repositories hosted on platforms such as GitHub. This combination has made Git the foundation of modern web development practices.

Understanding what Git does and how it fits into a GitHub-based workflow will help you see how developers manage code changes, experiment safely, and collaborate without overwriting each other’s work.

terms to know
Git
A distributed version control system that records snapshots of files over time, allowing developers to track changes, restore previous versions, and manage multiple lines of development.
Distributed Version Control System
A version control system where every developer has a complete copy of the project and its entire history on their local machine.

2a. Git as a Distributed Version Control System

Git is a distributed version control system, which means every developer working on a project has a complete copy of the project and its history on their own computer. This allows developers to track changes, create commits, and work with branches even when they are not connected to the internet.

In Git, a project is stored in a repository. A repository contains all project files along with the complete history of changes. When you use Git, you typically have a local repository on your computer and a remote repository stored on a platform such as GitHub.

The local repository allows developers to work independently and commit changes as they go. The remote repository on GitHub acts as a shared version of the project that can be used for backup, collaboration, and access from multiple devices.

Think of Git as the system that records and organizes changes and repositories as the containers that hold those changes. GitHub provides a shared, online space where remote repositories are stored and accessed.

The distributed nature of Git provides several advantages:

  • Speed: Most version control actions happen locally.
  • Offline work: Commits can be created without an internet connection.
  • Reliability: Every repository contains the full project history.
  • Collaboration: GitHub enables sharing, review, and coordination across contributors.
did you know
Git was created in 2005 by Linus Torvalds, the same person who created the Linux operating system. He built Git because he needed a fast, reliable way for thousands of developers around the world to collaborate on Linux. Today, Git is used for projects of all sizes, from personal websites to massive software applications.

term to know
Repository
A project tracked by Git that contains project files and the complete history of changes; a repository can exist locally on a computer and remotely on GitHub.

2b. Key Git Concepts

To understand how Git is used in practice, it is important to become familiar with several core concepts that describe how changes are recorded and managed within a repository.

A commit is a snapshot of a project at a specific moment. Each commit records what changed and includes a message explaining why the change was made. Commits create a clear timeline that shows how a project evolves over time and allow developers to return to earlier versions if needed.

A branch is an independent line of development within a repository. The main branch typically contains stable, working code, while additional branches allow developers to work on new features or experiments without affecting the main version of the project.

A merge is the process of combining changes from one branch into another. When work on a branch is complete, merging incorporates those changes into the target branch so the project can move forward as a single, updated version.

When working with GitHub, developers share their work by sending changes from their local repository to the remote repository and receiving updates from others. This exchange keeps local and remote versions of a project synchronized and supports collaboration.

key concept
Git manages changes locally through repositories, commits, branches, and merges, while GitHub stores remote copies of those repositories to support backup, sharing, and collaboration.

try it
You are working on a website project and make several changes to your files. Some changes are ready to be shared, while others are still experimental.
Which steps of the Git workflow help you decide what changes become part of the project’s history and which changes get shared with GitHub?
The staging step allows you to choose which changes are included in a commit. Creating a commit records those selected changes as part of the project’s history. Pushing commits to GitHub determines which committed changes are shared with the remote repository, while uncommitted or unpushed changes remain local.

terms to know
Commit
A snapshot of your project at a specific point in time, including a message describing what changed.
Branch
An independent line of development that allows you to work on features or experiments without affecting other branches.
Merge
The process of combining changes from one branch into another branch.


3. How Git Tracks Changes

Understanding how Git tracks your work helps explain what happens behind the scenes when you save progress, experiment with new ideas, or share updates through GitHub. Git uses a structured system of states and workflows to manage changes intentionally rather than automatically.

3a. The Three States of Git

Files in a Git repository can exist in three main states, and understanding these states helps clarify how Git manages your work.

The working directory is where you actually edit your files. This is your normal project folder where you write code, modify files, and delete things you do not need. Git watches this directory but does not automatically track every change you make.

The staging area (also called the “index”) is a preparation zone where you select which changes to include in your next commit. Think of it like packing a box before shipping—you choose exactly what goes in. This gives you control over your commits, allowing you to group related changes together logically.

The repository (specifically, the Git directory) is where Git permanently stores your committed snapshots. Once changes move from the staging area to the repository through a commit, they become part of your project’s permanent history.

An analogy might help. Imagine you are organizing photos from a vacation. Your working directory is like having all your photos spread out on a table. The staging area is like a photo album page where you are arranging which photos to keep. The repository is like your finished photo album on the shelf—a permanent record you can always look back at.

key concept
Git tracks changes through three states: the working directory (where you edit), the staging area (where you prepare changes), and the repository (where commits are permanently stored). Changes flow from the working directory to the staging area to the repository.

terms to know
Working Directory
The area where files are actively edited before being staged or committed.
Staging Area
A preparation space where developers select which changes from the working directory will be included in the next commit.

3b. A Basic Git Workflow

While this tutorial focuses on understanding concepts rather than specific commands, knowing the general workflow helps you see how the pieces fit together.

The flow of changes in Git: from the working directory to the staging area to the local repository, with arrows for push and pull to and from the remote repository.

A typical Git workflow follows these steps:

step by step
  1. Modify files in your working directory. You write code, fix bugs, or add new features just as you normally would.
  2. Stage changes you want to include in your next commit. You select specific files or changes to prepare for the snapshot.
  3. Commit the staged changes. Git creates a permanent snapshot of the staged files and stores it in the repository with your descriptive message.
  4. Repeat the process as you continue developing. Each commit adds another point to your project’s timeline.

This cycle of modify, stage, and commit creates a detailed history of your project. Each commit builds on the previous ones, forming a chain of snapshots that shows how the project evolved over time.

When working with branches, the workflow expands in this way:

  1. Create a new branch for a feature or experiment.
  2. Make commits on that branch as you work.
  3. When the feature is complete, merge the branch back into the main branch.
  4. Optionally, delete the feature branch since its changes now exist in the main branch.
After commits are created locally, developers can share their work by pushing commits to GitHub. A push command sends committed changes from a local repository to a remote repository so others can access them.

When working with others or across multiple devices, developers pull updates from GitHub to retrieve the latest shared changes and keep their local repository up to date.

terms to know
Push
The process of sending committed changes from a local repository to a remote repository on GitHub.
Pull
The process of retrieving updates from a remote repository on GitHub to keep a local repository up to date.


4. Benefits of Version Control

Now that you understand how Git tracks changes and how those changes are shared through GitHub, you can see why version control is a foundational practice in modern web development. These benefits apply whether you are working alone or as part of a team.

4a. Benefits for Individual Developers

Version control provides meaningful advantages even when a developer is working independently. By using branches, developers can experiment with new ideas without risking their stable code. If an experiment does not work, the branch can simply be abandoned. If it succeeds, the changes can be merged into the main branch.

Each commit creates a permanent record of the project at a specific moment, forming a timeline of changes over time. This complete history makes it easier to understand how a project evolved and allows developers to review past decisions or restore earlier versions when needed.

A commit timeline with labeled points for commits A through G, showing branches and merges along a horizontal line.

Version control also makes it easier to recover from mistakes. If a file is accidentally deleted or a bug is introduced, developers can compare the current code with previous versions or return the project to a known working state.

Storing a remote repository on GitHub provides an additional layer of protection for individual work. By keeping a copy of the project online, developers can access their work from multiple devices and reduce the risk of data loss if a computer fails.

big idea
For individual developers, version control supports safe experimentation, preserves a complete project history, enables recovery from mistakes, and provides reliable backup through GitHub.

4b. Benefits for Teams

Modern web development often involves multiple developers working on the same project at the same time. Version control helps teams coordinate their work, organize contributions, and manage changes without overwriting one another’s progress. Instead of editing the same files directly, team members can create separate branches for their own tasks. This allows developers to work on new features, bug fixes, or design updates simultaneously without interfering with one another’s progress.

Git also tracks who made each change and when it was made. This shared history helps teams understand how the project evolved over time and makes communication easier during development.

When multiple developers modify the same part of a file, Git identifies the overlapping changes as a merge conflict. Team members can then review the differences and decide which changes should remain. This process helps prevent accidental overwrites and encourages intentional collaboration.

GitHub further supports teamwork by providing a shared online repository where developers can review code, discuss changes, and manage project updates in one place. Teams often use pull requests to review proposed changes before merging them into the main branch.

key concept
For teams, version control enables parallel development through branches, tracks who changed what and when, helps resolve conflicts when changes overlap, supports code review processes, and provides a shared view of the project’s status.

try it
A small web development team has three members: one working on the homepage redesign, one fixing bugs in the shopping cart, and one adding a new user profile feature.
How does version control help them work simultaneously without interfering with one another?
Each team member can create their own branch for their specific work. The homepage designer works on a “homepage-redesign” branch, the bug fixer works on a “cart-fixes” branch, and the profile developer works on a “user-profile” branch. All three can make commits to their branches without affecting anyone else. When each feature is ready, it gets reviewed and merged into the main branch. If conflicts arise (perhaps the homepage and profile features both modified the navigation menu), Git identifies the conflicting changes so the team can resolve them intentionally.

summary
In this lesson, you explored version control by examining the problem it solves and what version control is, building a foundation for understanding why tracking changes is essential in software development. You then learned about introduction to Git, focusing on distributed version control and key concepts that explain how Git and GitHub support safe, organized development. Next, you examined tracking changes, including the three states of Git and the Git workflow, to understand how changes move from local edits to shared project history. Finally, you reviewed the benefits of version control for individual developers and teams, highlighting how version control supports experimentation, collaboration, and long-term project stability.

Source: THIS TUTORIAL WAS AUTHORED BY SOPHIA LEARNING. PLEASE SEE OUR TERMS OF USE.

Terms to Know
Branch

An independent line of development that allows you to work on features or experiments without affecting other branches.

Commit

A snapshot of your project at a specific point in time, including a message describing what changed.

Distributed Version Control System

A version control system where every developer has a complete copy of the project and its entire history on their local machine.

Git

A distributed version control system that records snapshots of files over time, allowing developers to track changes, restore previous versions, and manage multiple lines of development.

Merge

The process of combining changes from one branch into another branch.

Pull

The process of retrieving updates from a remote repository on GitHub to keep a local repository up to date.

Push

The process of sending committed changes from a local repository to a remote repository on GitHub.

Repository

A project tracked by Git that contains project files and the complete history of changes; a repository can exist locally on a computer and remotely on GitHub.

Staging Area

A preparation space where developers select which changes from the working directory will be included in the next commit.

Version Control

A system that records changes to files over time, allowing developers to track history, restore previous versions, and coordinate work among multiple people.

Working Directory

The area where files are actively edited before being staged or committed.