Beginner15 minutesGitLevel 1

Introduction to Git

Learning Objectives

By the end of this lesson, you'll be able to:

  • Understand Understand what version control is and why it is important
  • Explain Explain what Git is and how it differs from other version control systems
  • Identify Identify the three main states of Git (modified, staged, committed)
  • Understand Understand basic Git terminology and concepts
  • Recognize the value Git adds to your development workflow

Why This Matters:

Git is used by virtually every software team in the world. Learning it now will prepare you for collaboration, open-source contributions, and professional development workflows.

Before You Start:

You should be familiar with:

  • Basic command line usage
  • Basic file system operations (creating, moving, and deleting files)

Estimated time: 15 minutes

What is Version Control?

Before diving into Git, let's understand what version control is and why it's important.

Version control is a system that records changes to files over time so that you can recall specific versions later. It allows you to:

  • Track changes to your code
  • See who made each change
  • Revert to previous versions if something goes wrong
  • Collaborate with others without overwriting each other's work

Try It Yourself

This interactive timeline shows how Git tracks changes over time:

  • Commits: Each point represents a snapshot of your code
  • Branching: Different paths your project can take
  • Timeline: How your project evolves over time
Experimental BranchInitial CommitAdd FeatureFix BugRefactor CodeRelease v1.0

Pro Tip: Click on any commit in the timeline to see its details!

Life Without Version Control

Imagine you're working on a project without version control:

Project_v1.py

Your first version

Project_v2.py

After some changes

Project_final.py

The "final" version

Project_FINAL_v2.py

Wait, one more change

This approach quickly becomes messy and confusing as your project grows.

What is Git?

Git is a distributed version control system created by Linus Torvalds (the creator of Linux) in 2005. It's designed to handle everything from small to very large projects with speed and efficiency.

Key Features of Git

  • Distributed: Every developer has a full copy of the repository, including its history
  • Speed: Most operations are performed locally, making Git very fast
  • Data integrity: Git uses checksums to ensure your data is never corrupted
  • Non-linear development: Support for branching and merging
  • Staging area: A middle ground between your working directory and repository

Git is not GitHub!

Git is the version control system itself.

GitHub is a web-based platform that uses Git and adds collaboration features.

Other similar platforms include GitLab, Bitbucket, and Azure DevOps.

How Git Works

Git tracks changes to your files by taking "snapshots" over time. Think of each snapshot (called a "commit") as a save point in your project.

Working Directory(Your files)Staging Area(Prepared changes)Repository(Committed history)git addgit commit

The Three States

In Git, your files exist in one of three states:

Modified (Working Directory)

You've changed the file but haven't committed it to your database yet.

Staged (Staging Area)

You've marked a modified file to go into your next commit snapshot.

Committed (Git Directory)

The data is safely stored in your local database.

Why Learn Git?

For Professionals

  • Industry standard for version control
  • Essential skill for software development jobs
  • Enables collaboration in teams
  • Tracks project history and changes

For Students

  • Track changes to your assignments
  • Collaborate on group projects
  • Experiment without fear of breaking things
  • Build a portfolio of your work

For Everyone

  • Never lose your work
  • Time-travel through project history
  • Work on multiple features simultaneously
  • Understand how software is built

Learning Curve Alert: Git has a reputation for being difficult to learn. Don't worry! We'll break it down into manageable pieces, and with practice, it will become second nature.

Core Concepts

Before we dive into installation and commands, let's familiarize ourselves with some core Git terminology:

TermDefinition
Repository (Repo)A collection of files and their complete history
CommitA snapshot of your project at a specific point in time
BranchA parallel version of your repository where you can make changes without affecting the main version
MergeThe process of combining different branches
CloneCreating a copy of a repository
PullFetching and integrating changes from a remote repository
PushSending your committed changes to a remote repository

Hands-On Example: Your First Git Workflow

Let's walk through a simple example of how Git might be used in a typical workflow:

Scenario: Adding a Feature to a Website

Imagine you're working on a website and want to add a contact form.

1

Create a branch for your feature

This creates a safe space to work on your form without affecting the main website.

2

Make changes to your files

You create contact.html and add your form code.

3

Stage your changes

This tells Git you want to include this file in your next commit.

4

Commit your changes

This creates a snapshot of your changes with a descriptive message.

5

Merge your changes into the main branch

This integrates your contact form into the main website.

Summary

  • Git is a distributed version control system
  • It tracks changes to your files through commits (snapshots)
  • Git has three main states: modified, staged, and committed
  • Learning Git is essential for professional software development
  • Key concepts include repositories, commits, branches, and merges

Pro Tip: Don't worry about memorizing commands right now. Focus on understanding the concepts. The commands will become familiar with practice.

Challenge

Think about a project you're currently working on (it could be homework, a personal website, or even a document you're writing).

Question: How could version control benefit this project? What specific problems might Git solve for you?

🏁 Lesson Complete: Introduction to Git

Key Takeaways:

  • Version control tracks changes to files over time so you can recall specific versions later
  • Git is a distributed version control system where every developer has a full copy of the repository
  • Files in Git exist in three states: modified, staged, and committed
  • Key concepts include repositories, commits, branches, and merges
  • Learning Git is essential for professional software development

Learning Objectives Review:

Look back at what you set out to learn. Can you now:

  • ✅ Understand what version control is and why it is important Check!
  • ✅ Explain what Git is and how it differs from other version control systems Got it!
  • ✅ Identify the three main states of Git Can explain it!
  • ✅ Understand basic Git terminology and concepts Could teach this!

If you can confidently answer "yes" to most of these, you're ready to move on!

Think & Reflect:

💭 💭 Reflection Questions

  • How could version control benefit a project you are currently working on?
  • What problems might Git solve for you as a developer?
  • Why is distributed version control better than just saving copies of files?

🎯 Looking Ahead:

Now that you understand what Git is and why it matters, the next step is to install Git on your computer and configure it for use.

Recommended Next Steps

Continue Learning

Ready to move forward? Continue with the next tutorial in this series:

Installation & Setup

Related Topics

Explore these related tutorials to expand your knowledge:

Practice Projects

Apply what you've learned with these hands-on projects:

Clone and Explore

Clone a remote repository and explore its history.

gitclonehistory
Start Project

Additional Resources

Deepen your understanding with these helpful resources: