Skip to content

ga-curriculum/version-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Version Control

Session Time: 120 minutes


Table of Contents

  1. Introduction to Version Control
  2. Setting Up: Git Installation and Terminal/Git Bash
  3. Git Fundamentals: Initialization and Management
  4. Versioning Strategies for Collaboration
  5. AI-Assisted Documentation and Commits
  6. Wrap-Up and Reflection

Learning Objectives

Upon completion of this session, participants will be able to:

  • Install and configure Git and a terminal environment.
  • Initialize and manage repositories using Git commands.
  • Develop clear versioning strategies for collaboration.
  • Employ AI to draft professional commit messages and documentation.

Session Breakdown

Segment Topic Duration (minutes)
Concept I Introduction & Setup 30
Concept II Git Fundamentals & Repository Management 45
Concept III Collaboration Strategies & AI Documentation 30
Wrap-Up Wrap-Up and Reflection 15
Total 120 minutes

1. Introduction to Version Control

What is version control?

Version control is essentially a "save point" system for your project files. It allows you to track changes over time, revert to previous versions if something breaks, and collaborate with others without overwriting each other's work. Git is the most popular tool for doing this.

The Problem with "Final_v2_Real.zip"

Before Version Control Systems (VCS), developers managed changes by saving copies of folders (like Project_v1, Project_v2). This was error-prone and made combining work from two people nearly impossible.

Git solves this by tracking "snapshots" of your code over time. It allows you to travel back to previous versions and merge work from different developers.


2. Understanding the Terminal and Git Setup

Before we can start saving snapshots of our code, we need to understand the environment where Git operates and install the necessary software.

What is a Terminal?

Most people interact with computers using a Graphical User Interface (GUI)—clicking folders, dragging files, and using menus. A Terminal allows you to interact with your computer using a Command Line Interface (CLI). Instead of clicking, you type text commands to perform tasks.

Why do developers use the Terminal?

  • Power and Control: Many developer tools (like Git, web servers, and AI deployment tools) are built specifically for the command line.
  • Speed: Once you learn the commands, typing is often much faster than navigating through visual menus.
  • Automation: Terminal commands can be scripted together to automate repetitive tasks.

Basic Terminal Navigation

Before you can use Git to track a project folder, you must use the terminal to navigate into that folder. Here are the absolute essential commands you will use every day:

Command Action Example Usage
pwd OR cd Print Working Directory. Shows the exact path of the folder you are currently inside. pwd
ls OR dir List. Shows all files and folders inside your current directory. ls
cd <folder> Change Directory. Moves you inside the specified folder. cd Documents
cd .. Moves you "up" or "back" one folder level. cd ..
mkdir <name> Make directory. Creates a brand new folder. mkdir my-website

Practical Use Case: To start a new project, you would open your terminal, type cd Documents to move to your documents folder, type mkdir new-project to create the folder, and finally cd new-project to enter it. Only then are you ready for Git!

Installing Git

  • Windows Users: Download the Git installer from the official website (git-scm.com). During installation, this will also install Git Bash. Git Bash is highly recommended for Windows users because it provides a standard, industry-friendly command-line environment.
  • macOS Users: You can install Git by downloading the installer from the official site, or if you use Homebrew, by running brew install git in your terminal. You can use the built-in Terminal app found in your Applications folder.
  • Linux Users: Use your distribution's package manager (for example, sudo apt install git on Ubuntu).

Terminal and Git Bash Setup

Once installed, open your terminal application (Terminal on macOS/Linux, or Git Bash on Windows).

Before taking your first "snapshot", you need to introduce yourself to Git. Git wants to know who is making changes so it can label them accurately. Run these two commands, replacing the placeholder text with your actual name and email:

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

3. Git Fundamentals: Initialization and Management

Learning objective: Initialize and manage repositories using Git commands.

The Three States of Git

To manage a repository effectively, you must understand the three zones a file can reside in:

  1. Working Directory: The files you are currently editing on your computer.
  2. Staging Area: A preparatory zone where you list files to be included in the next snapshot.
  3. Repository (Local): The database where Git permanently stores the snapshots (commits).

Git Flow

The Basic Git Workflow

Here is the loop you will repeat constantly when using Git:

  • Step 1: Initialize: Turn a regular folder into a Git repository.
git init
  • Step 2: Check Status: See which files have been changed and what is currently staged.
git status
  • Step 3: Add (Stage): Move changes from your Working Directory to the Staging Area. You are telling Git, "I want to include this file in the next snapshot."
git add filename.txt
# OR to add all changed files at once:
git add .
  • Step 4: Commit: Take the snapshot. This moves the changes from the Staging Area to the Local Repository. Always include a clear message explaining what you changed.
git commit -m "Fixed the navigation bar bug"

Visualizing the Workflow

graph LR
    A[Working Directory] -- "git add" --> B[Staging Area]
    B -- "git commit" --> C[Local Repository]
    C -- "git push" --> D[Remote Repository like GitHub]
    
    style A fill:#ff9,stroke:#333
    style B fill:#9f9,stroke:#333
    style C fill:#99f,stroke:#333
    style D fill:#ccc,stroke:#333
Loading

Branching and Merging

This is Git's superpower. A branch allows you to create a parallel version of your project. You can work on a new feature in a separate branch without affecting the main "stable" version of your code.

  • Main (or Master): The default branch, usually containing the production-ready code.
  • Feature Branch: A temporary branch where you work on a specific task.

Common Branch Commands:

  • git branch feature-login: Create a new branch called "feature-login".
  • git checkout feature-login: Switch to that branch to start working.
  • git merge feature-login: When you are done, switch back to main and run this to combine your feature into the main code.

Remote Repositories (GitHub/GitLab)

So far, everything has happened on your computer. To back up your code or collaborate, you use a Remote (like GitHub).

  • Push: Uploads your local commits to the remote server.
git push origin main
  • Pull: Downloads new changes from the remote server to your computer (useful if a teammate added code).
git pull origin main

Summary of Terms and Core Commands

To initialize and manage a project, we use the command line (Terminal/Git Bash).

Command / Term Description Analogy
Repository (Repo) The project folder tracked by Git. -
Commit A saved snapshot of the project at a specific point in time. -
Clone Downloading an existing repository from the internet to your machine. -
Conflict When Git can't automatically merge branches because two people changed the exact same line of code in different ways. -
git init Starts tracking the current folder. Buying a blank photo album.
git status Shows which files have changed. Checking which photos are on the table.
git add <file> Moves a file to the Staging Area. Putting a photo in the plastic sleeve (but not sealing it).
git commit -m "msg" Saves the Staging Area to the Repository. Sealing the page and writing a caption.
git log Shows the history of changes. Flipping through the pages of the album.

4. Versioning Strategies for Collaboration

Learning objective: Develop clear versioning strategies for collaboration.

When working in teams, simply saving changes isn't enough. You need a strategy to ensure your changes don't overwrite your teammate's work.

Branching

A branch allows you to diverge from the main line of development and continue to work without messing up the main code.

  • Main Branch (usually main or master): This is the "production-ready" code. It should always be working.
  • Feature Branch: A temporary branch created to build a specific feature (e.g., feature/login-page).

Semantic Versioning (SemVer)

Professional software often uses a numbering system called SemVer (Format: MAJOR.MINOR.PATCH) to communicate the impact of changes.

  • MAJOR (1.0.0): Incompatible API changes (Breaking changes).
  • MINOR (1.1.0): Added functionality in a backward-compatible manner.
  • PATCH (1.1.1): Backward-compatible bug fixes.
gitGraph
    commit id: "v1.0.0"
    branch feature/navbar
    checkout feature/navbar
    commit id: "Add Logo"
    commit id: "Style Links"
    checkout main
    merge feature/navbar tag: "v1.1.0"
    commit id: "Bug Fix" tag: "v1.1.1"
Loading

5. Employing AI for Documentation and Commits

Learning objective: Employ AI to draft professional commit messages and documentation.

One of the hardest parts of version control is maintaining clear documentation. Developers often write lazy commit messages like "fixed stuff," which is unhelpful for the team. AI can serve as a documentation assistant.

The Code Diff Example

A git diff doesn't show the whole file; it only shows the lines that changed.

  • Red lines (-) are what existed before (and were removed).
  • Green lines (+) are what exist now (and were added).

Scenario: We are changing a website's title from "Welcome" to "Hello World".

Terminal Output:

diff --git a/index.html b/index.html
index 83c4.e92 100644
--- a/index.html
+++ b/index.html
@@ -5,7 +5,7 @@
 <body>
-    <h1>Welcome</h1>
+    <h1>Hello World</h1>
     <p>This is a paragraph.</p>
 </body>

The Change Diagram

The diagram below visualizes the two states (commits) that are being compared to generate the diff above.

gitGraph
   commit id: "Initial-Commit" tag: "v1.0.0"
   commit id: "Change-Title" tag: "v1.0.1"
   
   %% The 'diff' is the comparison between these two points
Loading

Generating Commit Messages

You can paste your code changes (a "diff") into an AI tool to generate a standardized commit message.

Prompt Strategy:

"I have made the following changes to my HTML file: changed the heading of my page and added a paragraph. Please generate a concise git commit message following the 'Conventional Commits' standard (e.g., feat:, fix:, style:)."

AI Output Example:

fix(html): update heading scheme

Automating Changelogs

A Changelog is a file (usually CHANGELOG.md) that lists every notable change made to a project.

Workflow with AI:

  1. Provide the AI with a list of your recent tasks or raw code edits.
  2. Prompt: "Based on these tasks, write a Markdown entry for my Changelog under version 1.2.0. Group changes by 'Added', 'Changed', and 'Fixed'."

6. Wrap-Up and Reflection

Discussion Questions:

  1. Why is it important to separate a "Bug Fix" (Patch) from a "Feature Update" (Minor) in version numbering?
  2. How did the idea of writing an AI-generated commit message compare to writing one manually? Were they clearer than what you might write on your own?

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors