Diploma in DevOps
Version Control with Git and GitHub/GitLab
•
Diploma
Version Control Foundations
Introduction and Context
Software development is an activity in which many files, decisions, contributors, and releases change over time. Source code is revised to add features, correct defects, improve security, support new platforms, and respond to user needs. Without a systematic way to record these changes, teams quickly lose the ability to answer basic questions: What changed? Who changed it? Why was it changed? Which version is running in production? Can an earlier working state be restored?
Version control provides the technical and organisational foundation for answering these questions. It is a system for recording changes to files so that individuals and teams can inspect history, coordinate work, recover earlier states, and manage releases. Although version control is strongly associated with source code, it can also manage configuration files, infrastructure definitions, documentation, database scripts, test data specifications, and other text-based artefacts.
For DevOps, version control is more than a developer convenience. It is a central mechanism for collaboration, automation, traceability, and controlled change. Build pipelines, tests, security checks, deployment processes, and infrastructure automation can all be triggered from version-controlled changes. Consequently, understanding version control is a foundation for professional software delivery and digital transformation.
Learning Objectives
By the end of this chapter, you should be able to:
Define version control and explain its purpose.
Describe the historical evolution of version-control systems.
Use essential terminology such as repository, revision, commit, branch, merge, tag, and checkout.
Distinguish local, centralized, and distributed version-control models.
Explain the benefits and limitations of version control.
Relate version control to DevOps, CI/CD, governance, and digital transformation.
Select suitable version-control practices for a professional team.
The Purpose of Version Control
A version-control system (VCS) records successive states of a set of files. A recorded state is commonly called a revision, version, or commit, depending on the system. The system normally stores metadata such as the author, timestamp, message, and relationship to earlier states.
The principal purposes are:
Change recording: preserving a reliable history of modifications.
Recovery: restoring a known working state after an error.
Comparison: identifying differences between two states.
Collaboration: allowing multiple people to work on related files.
Branching: supporting parallel lines of development.
Integration: combining work from different contributors.
Release management: identifying and reproducing released versions.
Accountability: linking changes to people, tasks, reviews, and approvals.
Version control should not be confused with merely copying a folder. A manually copied folder may provide a backup, but it usually lacks reliable metadata, structured comparison, searchable history, controlled collaboration, and repeatable recovery. Version control treats change as an explicit, reviewable, and recoverable process.
Historical Evolution
Manual file naming
Early development teams often created copies such as program-final, program-final2, and program-final-revised. This approach is easy to start but becomes unreliable because filenames do not explain the exact relationship between copies. It is also difficult to identify which copy is authoritative.
Local version control
Local systems stored revision history on one computer. A developer could save successive states and compare or restore them. This model improved individual productivity but offered limited collaboration and weak resilience if the computer failed.
Centralized version control
Centralized systems introduced a shared server containing the authoritative repository. Developers checked files out, modified them, and committed changes back to the server. Examples historically include CVS and Subversion. Centralization simplified administration and gave organisations a single source of truth, but server availability and network access became important dependencies.
Distributed version control
Distributed systems, including Git and Mercurial, give each contributor a complete or near-complete repository history. Work can be committed locally and shared with other repositories later. This supports offline work, faster history operations, flexible collaboration, and stronger resilience. It also introduces additional concepts, including synchronization between repositories and the possibility of several valid copies of a project history.
Evolution from manual copies to local, centralized, and distributed version control
Figure: Evolution from manual copies to local, centralized, and distributed version control
Figure: Evolution from manual file copies to distributed version control.
Essential Terminology
Term
Meaning
Repository
A data structure that stores project files and their history.
Working tree
The files currently checked out for editing.
Revision
A recorded state of one or more files.
Commit
A saved set of changes with metadata and a message.
Parent
An earlier revision from which a commit derives.
Branch
A named or logical line of development.
Merge
The integration of changes from different lines of development.
Remote
Another repository used for sharing or backup.
Clone
Creation of a local repository from an existing repository.
Fetch
Downloading references and objects from another repository without necessarily changing the working tree.
Pull
A combined workflow that obtains remote changes and integrates them, depending on the tool and configuration.
Push
Sending local commits or changes to another repository.
Tag
A human-readable name attached to a particular revision, often a release.
Checkout or switch
Selecting a branch or revision for the working tree.
Conflict
A situation in which changes cannot be automatically combined.
Diff
A representation of differences between file states.
Repository host
A service that stores and collaborates around repositories, such as GitHub or GitLab.
Protected branch
A branch subject to rules such as review or successful tests before integration.
A useful distinction is between a commit and a push. A commit records work in a local repository; a push transfers commits to another repository. A developer may commit several times while offline and push later. Similarly, a repository host is not itself the version-control system: Git is a version-control tool, while GitHub and GitLab are platforms that provide repository hosting, review, access control, issue tracking, automation, and other services.
Core Concepts and Models
States and change history
A project can be viewed as a sequence or graph of recorded states. Each commit normally identifies its parent commit, allowing the system to follow history. In distributed systems, history may form a directed acyclic graph rather than a single line because branches and merges create multiple paths.
Version-control systems generally store differences efficiently, but users should think in terms of recoverable project states rather than assuming that every system stores only simple line-by-line patches. Git, for example, uses objects and content-addressed identifiers, while its user experience presents commits, trees, and files.
Branches
A branch allows work to proceed independently. Common uses include feature development, release maintenance, and experimentation. A branch is not automatically a complete environment or a permanent organisational boundary. Excessive, long-lived branches can increase integration difficulty and delay feedback.
Merging and conflicts
A merge combines histories or file changes. Automatic merging is possible when the system can determine compatible changes. A conflict occurs when human judgement is needed, such as when two contributors modify the same lines in incompatible ways. Conflict resolution must be followed by validation and testing; accepting a syntactically valid merge does not guarantee correct behaviour.
Tags and releases
A tag gives a stable human-readable name to a revision, such as v2.1.0. A release may also include compiled artefacts, release notes, approval records, and deployment metadata. A tag alone does not guarantee reproducibility if dependencies, build tools, or external services are uncontrolled.
Local, Centralized, and Distributed Models
Dimension
Local
Centralized
Distributed
Main history location
Individual computer
Shared server
Each clone plus shared remotes
Offline commits
Usually yes
Usually no
Yes
Central availability dependency
Low for local work
High
Low for local work, higher for collaboration
Collaboration
Limited
Directly server-mediated
Repository synchronization and hosting
Administrative simplicity
High for one user
High central control
More concepts and policies
Resilience
Weak if one device fails
Depends on server backup
Multiple history copies, but not automatic safety
Typical examples
RCS-like tools
CVS, Subversion
Git, Mercurial
Local model
The local model is suitable for individual experimentation or historical tracking on a single machine. Its main limitation is that collaboration, backup, access control, and shared review require additional systems.
Centralized model
In a centralized model, the server is the authoritative repository. This makes permissions, backups, and policy enforcement relatively straightforward. However, server outages can interrupt work, and developers usually need network access for many operations. Centralization also creates a stronger operational requirement to protect the central repository.
Distributed model
In a distributed model, each clone can contain project history. Developers can inspect history, create commits, and create branches locally. A remote repository is commonly used as a collaboration hub, but it is technically one repository among several. Distributed does not mean unmanaged: teams still need rules about which repositories are authoritative, who may push, how changes are reviewed, and how releases are signed or approved.
Benefits of Version Control
Reliability and recovery
A documented history allows teams to identify when a defect was introduced and restore a known state. Recovery is effective only when commits are frequent enough, repositories are backed up, and important artefacts are actually tracked.
Collaboration and parallel work
Branches and merges permit multiple contributors to work without overwriting one another. Code review platforms add discussion, approval, automated checks, and an auditable integration path.
Traceability and compliance
A commit can be linked to a requirement, issue, review, test result, or deployment. This supports regulated environments and incident investigation. Traceability is valuable evidence, but it is not proof that the change was correct; quality still depends on review and testing.
Automation and repeatability
Version-controlled pipeline definitions, infrastructure-as-code files, and configuration templates allow environments and delivery processes to be reviewed and reproduced. The principle often called “everything as code” extends version-control practices beyond application source code.
Knowledge preservation
History documents technical decisions and enables new team members to understand how a system evolved. Commit messages and architectural documentation are more useful than unexplained snapshots.
Limitations and Risks
Version control does not automatically produce good software. Important limitations include:
Human error: a user may commit the wrong file, resolve a conflict incorrectly, or write an uninformative message.
Sensitive-data exposure: committing passwords, private keys, personal data, or proprietary material can create lasting risk. Removing a file from the latest commit may not remove it from historical objects or clones.
Repository size: large binary files and generated artefacts can make clones and operations slow. Large-file extensions or artefact repositories may be more appropriate.
Merge complexity: parallel development can create costly integration conflicts.
False confidence: a clean history does not establish security, correctness, or legal compliance.
Availability and access risks: hosted repositories can be unavailable, misconfigured, compromised, or subject to vendor dependency.
Inappropriate content: frequently changing build outputs, caches, operating-system files, and secrets usually do not belong in the source repository.
Governance overhead: branch rules, reviews, permissions, retention, and signing require time and competent administration.
A repository is therefore one part of a broader information-management and software-assurance system.
Version Control in DevOps
DevOps seeks to reduce the separation between development and operations while improving delivery speed, stability, and feedback. Version control supports this through a common, inspectable record of intended change.
A typical flow is:
A developer or operations engineer changes application code, a test, a pipeline definition, or infrastructure code.
The change is committed to a branch.
A pull request or merge request initiates peer review and automated checks.
Continuous integration builds the software and runs tests and security analysis.
An approved change is merged into an integration or main branch.
A delivery pipeline packages and deploys the selected revision.
Monitoring and operational feedback inform subsequent changes.
This creates a feedback loop between planning, coding, testing, deployment, and operation. The exact branching strategy varies. Trunk-based development emphasises small, frequent integrations into a main line, often using feature flags for incomplete functionality. A release-branch model may be appropriate where several supported versions must be maintained. Neither model is universally best; the choice should reflect release frequency, regulatory needs, team structure, and system risk.
A mature DevOps practice treats the repository as a product of governance as well as technology. Required reviews, automated tests, secret scanning, signed commits or tags, protected branches, and deployment approvals can reduce risk. These controls should be proportionate: excessive approval barriers can encourage workarounds and slow feedback.
Version Control and Digital Transformation
Digital transformation is not simply the purchase of cloud tools. It involves changing how an organisation creates value through digital capabilities, data, automation, and operating models. Version control contributes by making digital work more transparent, modular, and reproducible.
For example, an organisation can manage application source, infrastructure definitions, data-processing pipelines, compliance policies, and documentation in coordinated repositories. Automated workflows can test changes before they reach customers. Audit records can connect business requirements to deployed revisions. Teams can therefore move from informal, person-dependent practices to repeatable organisational capabilities.
However, technology alone does not transform an organisation. Effective transformation also requires skills, leadership, suitable processes, security controls, investment in platform engineering, and willingness to learn from failure. A repository full of unreviewed changes is not digital maturity.
Professional Practices
A diploma-level practitioner should adopt the following practices:
Create small, coherent commits that represent one logical change.
Write messages that explain intent, not merely file names.
Review changes before integration, especially security and infrastructure changes.
Keep branches short-lived where rapid integration is appropriate.
Pull or fetch regularly and resolve conflicts early.
Never commit secrets; use secret managers and scanning tools.
Exclude generated files and local configuration unless they are intentionally managed.
Tag releases and record the exact revision deployed.
Protect important branches and require automated checks.
Back up repositories and test restoration, not merely backup creation.
Document contribution, branching, release, and emergency-change procedures.
Treat history as public to everyone who can access the repository; do not place confidential information in commit messages.
Illustrative Case: Northstar Retail Platform
Background
Northstar Retail, a fictional medium-sized retailer, operated an online store and several warehouse services. Developers stored source code in shared folders, while operations engineers maintained deployment scripts on a separate server. Releases were infrequent and difficult to reproduce.
Problem
A production deployment introduced an inventory defect. The team could not determine which change caused it, which configuration had been used, or whether the previous release could be restored. The incident exposed both technical and organisational weaknesses.
Analysis
The organisation lacked a shared repository, consistent commit history, automated testing, and a defined release identifier. Source code and operational scripts had diverged. Several credentials were also stored in deployment files. The problem was therefore not simply the absence of Git; it was the absence of controlled change management.
Approach and solution
Northstar placed application code, tests, infrastructure definitions, and deployment workflows in version-controlled repositories. Secrets were moved to a managed secret store. The team adopted short-lived branches and merge requests, with mandatory review and automated tests. Each production deployment recorded the repository commit and generated a release tag. A staging environment was created so that the deployment workflow could be tested before production.
The team initially considered requiring two approvals for every change. It instead required one peer approval for ordinary changes and two approvals for high-risk infrastructure or security changes. This balanced governance with delivery speed.
Outcome
When a later inventory problem occurred, the team identified the relevant commit, compared it with the preceding revision, reproduced the deployment in staging, and rolled back to the previous tagged release. Investigation also showed that the defect had passed unit tests, leading to a new integration test rather than a purely procedural response.
Learning points
Version control improves incident response by preserving evidence and recoverable states.
Application and operational artefacts should be coordinated when they change together.
Tags and deployment records are essential for release traceability.
Automated checks complement, but do not replace, human review.
Governance should be risk-based rather than needlessly bureaucratic.
Ethical, Security, and Governance Considerations
Version-control records may contain contributor identities, work patterns, customer-related examples, or sensitive technical information. Organisations should apply least-privilege access, retention rules, appropriate repository visibility, and secure authentication. Personal data should not be committed unnecessarily, and access logs should be handled according to applicable privacy and employment requirements.
Open-source use introduces licence obligations. A project may need to preserve copyright notices, provide licence texts, disclose source under particular conditions, or track dependencies. Copying code into a repository without understanding its licence can create legal and ethical risks.
AI coding assistants add another governance question. Generated code should be reviewed for correctness, security, licence compatibility, and accidental disclosure of confidential material. AI-generated commits should not be treated as authoritative merely because they compile. The normal standards of authorship, review, testing, and accountability remain applicable.
Contemporary Developments
Modern Git hosting platforms combine repositories with issue tracking, code review, package registries, runners, security scanning, and deployment environments. Software supply-chain security increasingly uses dependency scanning, provenance records, signed artefacts, and policy enforcement. Infrastructure and policy as code extend version control into operations and governance.
These developments increase capability but also concentration risk. A team should understand its provider’s backup, export, retention, identity, and incident-recovery arrangements. A distributed local clone is not a complete business-continuity plan if it omits protected branches, release artefacts, issues, reviews, and secrets-management configuration.
Chapter Summary
Version control is a disciplined system for recording, comparing, sharing, and recovering changes to digital artefacts. It evolved from manual file copies through local and centralized systems to distributed systems such as Git. Core concepts include repositories, working trees, commits, branches, merges, remotes, tags, and conflicts.
Local systems support individual history, centralized systems provide a shared server authority, and distributed systems provide local repositories that synchronize with remotes. Each model offers trade-offs involving collaboration, availability, administration, resilience, and complexity.
Version control supports recovery, collaboration, traceability, automation, compliance, and knowledge preservation, but it cannot by itself ensure quality or security. Secrets, large binaries, careless merges, weak backups, and excessive governance remain risks. In DevOps, version control connects change to review, testing, deployment, monitoring, and feedback. In digital transformation, it helps organisations replace informal, person-dependent work with repeatable and auditable practices.
Professional practice requires meaningful commits, secure repositories, reviews, automated checks, release tags, tested backups, controlled access, and appropriate governance. The central principle is that every important change should be understandable, reviewable, and recoverable.
Key Terms
Version control: A system for recording and managing changes to files.
Repository: A store containing project files and version history.
Working tree: The files currently available for editing.
Revision: A recorded state of files.
Commit: A saved logical set of changes with metadata.
Branch: An independent line of development.
Merge: The combination of changes from different histories.
Remote: Another repository used for synchronization or collaboration.
Clone: A local copy of a repository and its history.
Fetch: Obtaining changes or references from another repository.
Push: Sending local commits to another repository.
Tag: A named reference to a particular revision.
Conflict: A change-combination problem requiring human resolution.
Diff: A representation of differences between states.
Centralized version control: A model based on a shared authoritative server.
Distributed version control: A model in which repositories contain local project history.
Continuous integration: Frequent integration of changes with automated build and test activities.
Protected branch: A branch governed by rules such as reviews and passing checks.
Infrastructure as code: Managing infrastructure definitions in machine-readable, version-controlled files.
Traceability: The ability to connect requirements, changes, reviews, tests, and releases.
Review Questions
Short Answer Questions
What problem does version control solve that ordinary file copying does not solve reliably?
Distinguish a commit from a push.
What is the purpose of a branch?
State two differences between centralized and distributed version control.
Why should secrets not be committed to a repository?
Long Answer Questions
Explain the historical evolution from manual file copies to distributed version control and discuss the main improvement at each stage.
Compare local, centralized, and distributed version-control models in terms of availability, collaboration, administration, and resilience.
Explain how commits, branches, merges, tags, and remotes work together in a professional development workflow.
Discuss the benefits and limitations of version control for software quality, security, compliance, and incident recovery.
Explain how version control supports DevOps and digital transformation without being sufficient to achieve either by itself.
Analytical / Application Questions
A team frequently overwrites one another’s files, cannot reproduce its last release, and stores deployment scripts separately from application code. Diagnose the underlying problems and propose a staged version-control improvement plan.
A developer accidentally commits a private access key and then deletes it in the next commit. Analyse why this remains a security incident and identify the appropriate response.
A regulated organisation wants two approvals for every change, while its delivery team argues for rapid integration. Design a risk-based governance approach that preserves traceability without creating unnecessary delay.
Multiple Choice Questions with Answers
Question 1
Which statement best defines version control?
A. A system that records and manages changes to digital files
B. A tool that permanently prevents software defects
C. A service used only to compile source code
D. A backup method that stores only the latest file copy
Correct Answer: A. A system that records and manages changes to digital files
Question 2
What is the main distinction between a commit and a push in Git?
A. A commit creates a branch, while a push deletes one
B. A commit records changes locally, while a push transfers them to another repository
C. A commit downloads changes, while a push reviews them
D. A commit tags a release, while a push merges all branches
Correct Answer: B. A commit records changes locally, while a push transfers them to another repository
Question 3
Which model normally provides each contributor with a local repository containing project history?
A. Manual file-copy model
B. Centralized version control
C. Distributed version control
D. Read-only archival control
Correct Answer: C. Distributed version control
Question 4
What is the primary purpose of a branch?
A. To provide an independent line of development
B. To encrypt every file in a repository
C. To replace the repository backup process
D. To guarantee that merges never conflict
Correct Answer: A. To provide an independent line of development
Question 5
Which practice most directly helps identify the exact revision deployed to production?
A. Deleting old branches after every commit
B. Using a release tag and recording its revision
C. Keeping deployment scripts outside version control
D. Renaming files with the word final
Correct Answer: B. Using a release tag and recording its revision
Question 6
What should normally happen after resolving a merge conflict?
A. The unresolved markers should be left in the files
B. The affected files should be validated and tested
C. The entire repository should be deleted
D. All branches should be merged automatically again
Correct Answer: B. The affected files should be validated and tested
Question 7
Which item is generally inappropriate to commit directly to a source repository?
A. A unit test
B. A deployment workflow definition
C. A private access key
D. A documented configuration template without secrets
Correct Answer: C. A private access key
Question 8
How does version control support continuous integration?
A. It provides a source of changes that can trigger automated builds and tests
B. It removes the need for testing by preserving history
C. It ensures every merge is semantically correct
D. It replaces monitoring in production
Correct Answer: A. It provides a source of changes that can trigger automated builds and tests
Question 9
What is a significant limitation of version control?
A. It cannot record authorship information
B. It cannot support parallel development
C. It does not by itself guarantee software quality or security
D. It cannot restore an earlier recorded state
Correct Answer: C. It does not by itself guarantee software quality or security
Question 10
Why can a repository host not be treated as identical to Git?
A. Git is a version-control tool, while a host provides collaboration and repository services around repositories
B. Git is only a cloud storage provider, while a host is a compiler
C. Git cannot store history, while a host stores only file names
D. A host is always distributed, while Git is always centralized
Correct Answer: A. Git is a version-control tool, while a host provides collaboration and repository services around repositories
Version Control with Git and GitHub/GitLab
Chapter 1
of 14