Session Time: 120 minutes
- Introduction to Version Control
- Setting Up: Git Installation and Terminal/Git Bash
- Git Fundamentals: Initialization and Management
- Versioning Strategies for Collaboration
- AI-Assisted Documentation and Commits
- Wrap-Up and Reflection
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.
| 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 |
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.
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.
Before we can start saving snapshots of our code, we need to understand the environment where Git operates and install the necessary software.
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.
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 Documentsto move to your documents folder, typemkdir new-projectto create the folder, and finallycd new-projectto enter it. Only then are you ready for 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 gitin 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 giton Ubuntu).
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"
Learning objective: Initialize and manage repositories using Git commands.
To manage a repository effectively, you must understand the three zones a file can reside in:
- Working Directory: The files you are currently editing on your computer.
- Staging Area: A preparatory zone where you list files to be included in the next snapshot.
- Repository (Local): The database where Git permanently stores the snapshots (commits).
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"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
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 tomainand run this to combine your feature into the main code.
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 mainTo 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. |
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.
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
mainormaster): 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).
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"
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.
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 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
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
A Changelog is a file (usually CHANGELOG.md) that lists every notable change made to a project.
Workflow with AI:
- Provide the AI with a list of your recent tasks or raw code edits.
- Prompt: "Based on these tasks, write a Markdown entry for my Changelog under version 1.2.0. Group changes by 'Added', 'Changed', and 'Fixed'."
Discussion Questions:
- Why is it important to separate a "Bug Fix" (Patch) from a "Feature Update" (Minor) in version numbering?
- 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?
