Skip to main content

Introduction to Version Control

In modern software development, working on code without version control is like writing a book without saving backups. You are bound to lose data or make breaking changes that you cannot undo.


18.1.1 The File Versioning Nightmare

Have you ever saved a project file like this?

  • app.py
  • app_final.py
  • app_final_fixed.py
  • app_backup_june30.py

This is called manual versioning, and it becomes a massive mess. If a bug is introduced, finding which version introduced it is a nightmare. Version Control Systems (VCS) solve this problem by tracking changes to your files systematically.


18.1.2 What is Git?

Git is a local software tool that runs on your computer. It takes "snapshots" of your project directory at points you choose.

  • Every time you save a snapshot, Git records what lines of code were added, removed, or modified.
  • You can roll back to any previous snapshot at any time, protecting you against accidental code damage.

18.1.3 Git vs. GitHub (The Core Difference)

Beginners often confuse Git and GitHub. They are different tools:

FeatureGitGitHub
What is it?A local command-line software tool.A cloud-based web hosting service.
Where does it run?Locally on your computer.On remote cloud servers.
Do you need internet?No, runs offline.Yes, requires an active connection.
Primary Use:Tracks files and commits changes locally.Backs up code online and facilitates collaboration.

18.1.4 Installing Git

Check if Git is already installed on your system by opening your terminal and typing:

git --version

If it is not installed, follow the setup for your Operating System:

  • Windows: Download the installer from git-scm.com. Run the setup, keeping all default configuration options.
  • macOS: Open a terminal and run git --version. If it is missing, macOS will prompt you to install the Xcode Command Line Tools, which includes Git. Alternatively, if you use Homebrew, run:
    brew install git
  • Linux (Ubuntu/Debian): Run:
    sudo apt update
    sudo apt install git

Configuring Git (First Time Only)

Set up your identifier name and email address so Git commits list you as the author:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"