Overview

This lecture provides a comprehensive introduction to Version Control Systems (VCS), critical tools for managing changes to files and code over time. We'll explore the evolution from local and centralized systems to modern distributed version control, with a focus on Git - the most widely used VCS today, used by millions of developers worldwide.

Key Statistic 99% of developers use some form of version control. GitHub, the largest Git hosting platform, has over 200 million repositories.

Lecture Material (PDF)


CI/CD Overview (PDF)

Types of Version Control Systems

Version control systems have evolved significantly over time. Understanding the different types helps you appreciate the advantages of modern distributed systems like Git.

  • Local Version Control

    Early VCS solutions like RCS stored file revisions in a special format on the local machine. Local VCS laid the foundation for more sophisticated version control.

  • Centralized VCS (CVCS)

    Systems like CVS and Subversion use a central server to store files and their history. CVCS were widely adopted in the early 2000s for team collaboration.

  • CVS (Concurrent Versions System)

    One of the first popular CVCS, allowing developers to check out and check in changes to a central repository. Introduced features like branching and merging.

  • Subversion (SVN)

    Improved upon CVS by adding features like atomic commits and better handling of binary files. Still used by many organizations for its reliability and simplicity.

  • Distributed VCS (DVCS)

    Systems like Git and Mercurial allow each developer to have a complete copy of the repository. DVCS offer greater flexibility and resilience compared to CVCS.

  • Git History

    Created by Linus Torvalds in 2005 for the development of the Linux kernel. Git is now the most popular VCS, used by millions of developers worldwide.


Git Fundamentals

Git tracks changes to files in a special database called a repository. Think of Git as a snapshot tool for your project's files, capturing the state at each commit.

  • Git Repository

    A Git repository stores the entire history of a project, including all branches and commits. It contains all the metadata needed to track changes over time.

  • Staging Area

    A temporary holding area for changes before they are committed. Staging allows you to select specific changes for each commit, giving you fine-grained control.

  • Commits

    A commit is a snapshot of the changes in the staging area at a specific point in time. Each commit has a unique identifier (SHA) and a message describing the changes.

  • Branches

    Branches allow you to work on different features or bug fixes in parallel without affecting the main codebase. Essential for managing complex projects.

  • Merging

    Merging combines changes from different branches into a single branch. Git provides tools to help resolve conflicts when the same lines are modified.

  • Remotes

    Remotes are copies of a repository hosted on a server, such as GitHub or GitLab. They enable collaboration and provide backups of your code.

Best Practice Committing regularly is good practice for tracking your progress. Each commit should represent a logical unit of work with a clear, descriptive message.

Git Workflow

The typical Git workflow involves a series of operations: cloning, branching, committing, merging, and pushing changes. Mastering this workflow is essential for effective code management.

  • Clone

    Creates a local copy of a remote repository. Cloning is the first step to contributing to a project or starting work on an existing codebase.

  • Branch

    Create a new branch to work on a feature or fix. This isolates your changes from the main codebase until they're ready to be merged.

  • Stage & Commit

    Use git add to stage changes, then git commit to save them. Stage allows you to select specific changes for each commit.

  • Fetch

    Downloads changes from a remote repository without merging them into your local branch. Fetching keeps your local repository up-to-date with the remote.

  • Pull

    Downloads changes from a remote repository and merges them into your local branch. Pulling is a combination of fetching and merging.

  • Push

    Uploads your local commits to a remote repository. Pushing shares your changes with others and creates backups of your work.


Essential Git Commands

These are the core Git commands you'll use daily. Understanding these commands is fundamental to working effectively with version control.

  • git init

    Initializes a new Git repository in the current directory. Start tracking your project's history with this command.

  • git clone [url]

    Creates a local copy of a remote repository. Clone a repository to start collaborating or working on a project.

  • git add [file]

    Stages changes for the next commit. Use 'git add .' to stage all changes, or specify individual files for selective staging.

  • git commit -m [message]

    Creates a new commit with the specified message. Write clear, descriptive commit messages that explain what changed and why.

  • git status

    Shows the current state of the repository, including staged and unstaged changes. Use this to see what has changed since your last commit.

  • git log

    Displays the commit history of the current branch. Review your project's history, including commit messages, authors, and timestamps.

  • git branch [name]

    Lists all branches or creates a new branch. Branching is a powerful tool for managing different versions of your code.

  • git checkout [branch]

    Switches to a different branch or restores files. Use this to navigate between branches or undo changes to specific files.


Collaboration & Best Practices

Version control truly shines when working with teams. These practices help ensure smooth collaboration and maintain code quality.

  • Pull Requests

    A mechanism for proposing changes and requesting code review before merging. Essential for maintaining code quality in team environments.

  • Code Review

    Reviewing changes before they're merged helps catch bugs, improve code quality, and share knowledge across the team.

  • Branch Naming

    Use descriptive branch names like 'feature/user-auth' or 'bugfix/login-error'. Clear naming helps team members understand the purpose of each branch.

  • Commit Messages

    Write clear, concise commit messages. Start with a verb (Add, Fix, Update) and explain what the change does, not how it does it.

  • Conflict Resolution

    When multiple developers modify the same code, conflicts occur. Git provides tools to identify and resolve these conflicts during merging.

  • Backup & Recovery

    Remote repositories serve as backups. With Git's complete history, you can recover from mistakes and restore previous versions of your code.

Team Tip Choose the right VCS for your project's needs. For most modern projects, Git with a hosting platform like GitHub or GitLab provides the best collaboration features.

Labs & Practical Exercises

Reinforce your understanding of Version Control Systems with hands-on lab exercises. These labs will guide you through using Git for version control in real projects.


Tools & Further Reading

Enhance your understanding of version control with these resources and tools.

GitHub

GitHub

World's largest code hosting platform.

Link
Git Documentation

Git Documentation

Official Git reference and tutorials.

Link
VLE Page

VLE Page

Course management and resources.

Link
Practice Tip The best way to learn Git is by using it daily. Create a personal project and practice the full workflow: branching, committing, merging, and collaborating.