0% found this document useful (0 votes)
2 views

Structured Programming Lab Lecture 1

The document provides an overview of Version Control Systems (VCS), emphasizing their importance in tracking code changes, facilitating collaboration, and reducing data loss. It introduces Git as a popular distributed version control system and GitHub as a cloud-based hosting service that enhances collaboration and automation. The document also outlines basic Git workflows and includes a lab task for setting up a Git repository and managing branches.

Uploaded by

calebndivo16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Structured Programming Lab Lecture 1

The document provides an overview of Version Control Systems (VCS), emphasizing their importance in tracking code changes, facilitating collaboration, and reducing data loss. It introduces Git as a popular distributed version control system and GitHub as a cloud-based hosting service that enhances collaboration and automation. The document also outlines basic Git workflows and includes a lab task for setting up a Git repository and managing branches.

Uploaded by

calebndivo16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

The Co-operative University of Kenya

Department of Computer Science and


Information Technology
Lecture Notes: Version Control Systems &
Code Collaboration
BCSE 1203: Structured Programming Lab
Dr. Shem Mbandu Angolo, PhD.
Feb - May 2025

1 Introduction to Version Control Systems


(VCS)
1.1 What is Version Control?
Version Control is the process of tracking and managing changes to software
code, documents, or any digital content over time. It enables developers to
revert to previous versions, compare changes, and collaborate efficiently.
Key Benefits of Version Control:
• Tracks Code History: Every modification made to a file is recorded,
allowing developers to revisit or restore previous states.
• Facilitates Collaboration: Multiple developers can work on the same
project simultaneously without overwriting each other’s work.
• Reduces Risk of Data Loss: Version control maintains a complete
history of the project, safeguarding against accidental deletions or er-
rors.
• Supports Branching and Merging: Developers can work on fea-
tures independently and merge them back into the main codebase when
ready.

1
• Provides Documentation of Changes: Every commit in a ver-
sion control system is accompanied by a message describing what was
changed, creating a valuable reference for team members.

1.2 Types of Version Control Systems


There are three main types of Version Control Systems:

1.2.1 Local Version Control


• The simplest form of version control, where changes are manually saved
as different copies of the same file (e.g., file v1.c, file v2.c).

• This method is prone to human errors and lacks efficient collaboration


features.

• Example: Using file backups or manual renaming to store different


versions of code.

1.2.2 Centralized Version Control (CVCS)


• A single central server stores all versions of the project, and developers
connect to it to fetch or update code.

• Advantages:

– Everyone works on the same central repository, ensuring consis-


tency.
– Easier to enforce security and access control.

• Disadvantages:

– If the central server crashes, the entire project history may be lost.
– Requires a constant network connection to interact with the repos-
itory.

• Examples: CVS (Concurrent Versions System), SVN (Subversion), Per-


force.

2
1.2.3 Distributed Version Control (DVCS)
• Each developer has a full copy of the entire repository, including all
versions and history.
• Advantages:
– Developers can work offline, committing changes locally before
syncing with a remote repository.
– Better redundancy: No single point of failure, as every copy of the
repository contains a complete project history.
• Examples: Git, Mercurial, Bazaar.
• Why Git is Popular? Git provides speed, flexibility, and powerful
branching/merging capabilities, making it the industry standard.

1.3 Why Use Version Control?


• Tracking Changes Over Time: Every modification is logged, so
developers can compare past versions and understand what changed
and why.
• Enabling Team Collaboration: Prevents code conflicts when mul-
tiple developers edit the same file.
• Managing Multiple Versions: Teams can maintain different branches
of a project for different purposes (e.g., development, testing, and pro-
duction).
• Reducing Development Errors: Bug-tracking is simplified as de-
velopers can analyze historical code changes.
• Providing Backup and Security: Remote repositories (e.g., GitHub,
GitLab) store code securely in the cloud.
• Integration with DevOps: Automates testing and deployment through
Continuous Integration/Continuous Deployment (CI/CD) pipelines.

2 Introduction to Git & GitHub


2.1 What is Git?
Git is a distributed version control system designed to handle everything
from small to very large projects with speed and efficiency.

3
2.2 What is GitHub?
GitHub is a cloud-based Git repository hosting service that provides
version control, collaboration, and automation for software projects.

2.3 Why Use Git & GitHub?


• Offline Work: Developers can commit code locally and synchronize
changes when online.

• Collaboration: Multiple developers can work on different branches


without conflicts.

• Branching and Merging: Allows parallel development of features and


bug fixes.

• Code History and Versioning: Helps track changes, revert versions, and
debug efficiently.

• Integration with DevOps: Automates testing and deployment pro-


cesses.

• Security and Access Control: Enables team-based access permissions.

3 Git Workflow Basics


3.1 Setting Up Git
To install Git:
sudo apt i n s t a l l g i t # Linux
brew i n s t a l l g i t # macOS
Configure Git:
g i t c o n f i g −−g l o b a l u s e r . name ”Your Name”
g i t c o n f i g −−g l o b a l u s e r . e m a i l ” your . email@example . com”

3.2 Initializing a Git Repository


mkdir m y p r o j e c t
cd m y p r o j e c t
git init

4
3.3 Adding and Committing Files
g i t add f i l e n a m e . c
g i t commit −m ” I n i t i a l commit”

4 Lab Task: Setting Up a Git Repository and


Managing Branches
Objective:

• Set up a Git repository.

• Create branches, switch between them, and merge them.

• Push the repository to GitHub.

Instructions:
# I n i t i a l i z e a Git r e p o s i t o r y
mkdir g i t l a b
cd g i t l a b
git init

# Create a new f i l e and commit i t


echo ” H e l l o , Git ! ” > h e l l o . t x t
g i t add h e l l o . t x t
g i t commit −m ”Added h e l l o . t x t ”

# Create and s w i t c h t o a new branch


g i t c h e c k o u t −b new−f e a t u r e

# Modify th e f i l e and commit changes


echo ” This i s a new f e a t u r e . ” >> h e l l o . t x t
g i t add h e l l o . t x t
g i t commit −m ” Updated h e l l o . t x t with a new f e a t u r e ”

# Switch back t o t he main branch and merge changes


g i t c h e c k o u t main
g i t merge new−f e a t u r e

# Push t he p r o j e c t t o GitHub

5
g i t remote add o r i g i n h t t p s : / / g i t h u b . com/ username / g i t l a b . g i t
g i t push −u o r i g i n main

5 Summary
• Version Control tracks changes, enables collaboration, and ensures code
security.

• Git is the industry-standard Distributed Version Control System.

• GitHub enhances Git with cloud storage, collaboration, and automa-


tion tools.

• Branching and merging allow developers to work in parallel.

• Hands-on practice with Git is essential for software engineers.

You might also like