Software Engineering Principles and Practices / DevOps vs Modern Practices

Version Control (Git Overview)

In Software Engineering, Version Control (also known as Source Control) is the practice of tracking and managing changes to software code. Git is the industry standard for version control—a distributed system that allows multiple developers to work on the same codebase simultaneously without overwriting each other's work.


1. Why Use Version Control?

Without a system like Git, developers would have to manually share files or keep folders like final_v1, final_v2_fixed. Git solves this by providing:

  • History: A complete log of every change made, by whom, and when.

  • Reversibility: The ability to "undo" a mistake and roll back to a previous working version.

  • Collaboration: Allowing many people to work on different features at the same time.

  • Branching: Creating "parallel universes" for experimentation without breaking the main code.


2. The Three States of Git

To understand how Git works, you must understand where your files live at any given moment:

  1. Working Directory: The actual files you are currently editing on your computer.

  2. Staging Area (Index): A "prep zone." You tell Git which specific changes you want to include in your next snapshot.

  3. Local Repository (.git): Where Git permanently stores the snapshots (commits) of your project on your machine.


3. Basic Git Workflow

A typical day for a developer involves these four commands:

  • git add: Moves changes from the Working Directory to the Staging Area.

  • git commit: Saves the staged changes as a permanent snapshot in the Local Repository.

  • git push: Sends your local commits to a Remote Repository (like GitHub or GitLab).

  • git pull: Fetches changes from the Remote Repository and merges them into your local files.


4. Branching and Merging

Branching is Git's most powerful feature. It allows you to diverge from the main line of work (the main or master branch) to fix a bug or build a feature in isolation.

  • Branching: Creating a pointer to a specific commit so you can work independently.

  • Merging: Combining the work from a feature branch back into the main branch once it is tested and approved.

  • Merge Conflict: Occurs when two people change the same line of code in different ways. Git asks the human to decide which version to keep.


📊 Centralized vs. Distributed Version Control

Feature

Centralized (SVN)

Distributed (Git)

Storage

One central server holds the history.

Every developer has a full copy of the history.

Offline Work

Impossible; you must be connected.

Fully supported; you only need internet to "push."

Speed

Slow (requires network for most tasks).

Extremely fast (most tasks are local).

Risk

High (if the server dies, history is lost).

Low (every laptop is a backup).


🛠️ Common Git Terms

  • Repository (Repo): The project folder containing all code and history.

  • Commit: A "save point" or snapshot of the project.

  • HEAD: A pointer to the latest commit in your current branch.

  • Clone: Downloading an existing repository from a remote server to your local machine.