Git & Version Control

Chapter 1
Version Control Foundations

Certificate in DevOps
Git & Version Control   •   Certificate

Version Control Foundations

Introduction

Software development is an activity of continuous change. Source code, configuration files, infrastructure definitions, documentation, test scripts, and deployment manifests are revised as requirements evolve. Without a disciplined way to record those changes, teams quickly lose the ability to answer basic but essential questions: What changed? Who changed it? Why was it changed? Which version was deployed? Can an earlier working state be restored?

Version control provides the organizational and technical foundation for answering these questions. It records the history of digital artifacts and enables people to coordinate changes safely. Although version control is strongly associated with software engineering, the underlying principles also apply to documentation, data-analysis notebooks, system configurations, and other digital assets.

Git is the most widely used modern version-control system. It supports local experimentation, collaborative development, automated delivery, and the traceability required by professional and regulated environments. Understanding Git begins not with memorizing commands, but with understanding the concepts of versions, snapshots, repositories, revisions, and change history.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Explain the purpose and value of version control.
  2. Distinguish files, snapshots, revisions, repositories, and branches.
  3. Describe how version control supports traceability and collaboration.
  4. Compare centralized and distributed version-control models.
  5. Explain Git’s object-based model and its role in DevOps.
  6. Identify practical, governance, and security considerations when using version control.

1. The Problem of Uncontrolled Change

A simple project may begin with a file named application.py. As development proceeds, users may create copies such as application-final.py, application-final2.py, and application-final-approved.py. These copies provide limited backup protection, but they do not reliably record the reason for each change, the person responsible, or the relationship between versions.

Uncontrolled change creates several risks:

  • Loss of work: A file may be accidentally overwritten or deleted.
  • Conflicting edits: Two people may change the same lines and unknowingly discard each other’s work.
  • Poor reproducibility: A team may be unable to recreate the exact source used for a release.
  • Weak accountability: It may be unclear who introduced a defect or approved a change.
  • Deployment uncertainty: The production system may not correspond to a clearly identified source version.
  • Slow recovery: Restoring a known-good state becomes difficult and error-prone.

Version control addresses these problems through an explicit history of change rather than a collection of informal copies.

2. What Is Version Control?

Version control is a system for recording, organizing, comparing, and restoring successive states of files or other digital artifacts. A version-control system (VCS) normally provides four capabilities:

  1. History: It records previous states and the changes between them.
  2. Identification: It gives revisions recognizable identifiers.
  3. Coordination: It helps multiple contributors work on shared artifacts.
  4. Recovery: It allows users to inspect or restore earlier states.

Version control is not the same as a backup system. A backup primarily preserves data against loss. Version control also explains how data changed, supports collaboration, and connects changes to human decisions, work items, tests, and releases. A mature engineering environment uses both version control and independent backups.

Important terminology

A working tree is the set of files currently checked out for editing. A change is a difference between two states. A revision is an identifiable recorded state or update. A commit is a recorded set of changes in Git. A repository is the data structure that stores version history and related metadata. A branch is a named line of development. A tag is a fixed name applied to a particular revision, commonly used to identify releases.

These terms are related but not interchangeable. A file on a developer’s computer is not automatically a revision; it becomes part of version history only when the user records it in the repository.

3. Files, Changes, and Snapshots

3.1 Difference-based thinking

Some version-control systems primarily describe a revision as a sequence of differences, or deltas, from an earlier revision. For example, a change might state that three lines were inserted and one line was removed. Delta representations can be storage-efficient, especially for large text files with small changes.

A delta is useful for understanding what changed, but reconstructing a complete file may require applying a chain of earlier deltas. Systems therefore use engineering strategies such as periodic full versions or optimized storage.

3.2 Snapshot-based thinking

Git is best understood as a snapshot-oriented system. A commit represents the state of tracked content at a particular point in time, together with metadata such as the author, message, parent commit, and timestamp. Git often reuses unchanged content internally rather than physically copying every file into every commit. Thus, “snapshot” describes the conceptual model; it does not imply wasteful duplication of all bytes.

A snapshot answers the question: “What did the project contain at this recorded point?” A diff answers: “How does one recorded state differ from another?” Both views are important. Snapshots support restoration and reproducibility; diffs support review and diagnosis.

3.3 Example of project history

Consider a small web service:

RevisionRecorded statePurpose
R1Initial service and testEstablish a working baseline
R2Input validation addedPrevent malformed requests
R3Logging improvedSupport operational diagnosis
R4Security fix appliedAddress a discovered vulnerability

If R4 introduces an unrelated failure, a team can compare R4 with R3, inspect the responsible change, or temporarily restore R3 while preparing a correction. The history is more informative than a folder containing four ambiguously named copies.

4. Repositories and Revisions

A repository stores the history of a project. In Git, the repository includes commit objects, references such as branches and tags, and configuration or metadata. The working tree is separate conceptually: it is the editable checkout derived from repository history.

A revision should be identifiable and stable enough to support communication. Git identifies commits using cryptographic object identifiers derived from their contents and associated metadata. Users commonly refer to commits through shortened identifiers, branch names, or tags. A branch name such as main is a movable reference to a commit, whereas a tag such as v2.0.0 is generally intended to identify a release point.

A commit normally has one or more parent commits. This creates a directed history. Ordinary development produces a sequence; merging combines histories and may create a commit with two or more parents. The resulting graph explains why Git can represent parallel development rather than only a single linear list.

Commit messages as technical documentation

A commit message should describe the intent of a change rather than merely restating its file names. “Validate payment reference before submission” is more useful than “Updated controller.” Good messages improve code review, incident investigation, release notes, and future maintenance.

5. Traceability and Accountability

Traceability is the ability to follow an artifact, requirement, or operational event through related records. In software delivery, traceability may connect:

requirement → issue → commit → code review → automated test → build artifact → deployment → monitoring event

This chain is not created automatically by Git alone. Git supplies a durable record of source changes, but teams must establish conventions and integrate tools to connect commits with issue trackers, review systems, build pipelines, and deployment platforms.

Traceability supports:

  • Defect analysis: Identify when and why a behavior changed.
  • Compliance: Demonstrate that controlled changes were reviewed and authorized.
  • Release management: Determine exactly which source revision produced a release.
  • Incident response: Compare the deployed revision with the current repository state.
  • Knowledge transfer: Help new team members understand project evolution.

Traceability should not become surveillance for its own sake. The purpose is reliable engineering and accountability, not excessive monitoring of individuals. Teams should distinguish authorship, review, approval, and automated execution, since these are different responsibilities.

6. Centralized and Distributed Version Control

6.1 Centralized model

In a centralized version-control system, a principal server stores the repository history. Developers obtain working copies from that server and usually need network access for many operations.

Advantages include:

  • A clear central authority and access-control point.
  • Familiar administration and backup arrangements.
  • Straightforward permissions and project ownership.
  • A single canonical location for organizational history.

Limitations include:

  • Dependence on server availability and network access.
  • Potential performance constraints for remote teams.
  • A central failure that can disrupt collaboration.
  • More limited support for private, local experimentation.

Centralized systems can be well engineered and remain appropriate in some organizations. “Centralized” does not mean unreliable; it describes where the primary history and coordination authority reside.

6.2 Distributed model

In a distributed version-control system (DVCS), each full clone normally contains repository history. Developers can create commits, inspect history, compare revisions, and create branches locally, often without network access. Collaboration occurs when repositories exchange commits through operations such as push and fetch.

Advantages include:

  • Fast local operations.
  • Offline commits and experimentation.
  • Multiple possible collaboration points.
  • Strong support for branching and merging.
  • Reduced dependence on a single always-available server for local work.

Limitations include:

  • More concepts for beginners to learn.
  • Multiple copies of history that require governance.
  • The need to understand synchronization and divergence.
  • Potential exposure of sensitive history in clones.

A distributed model does not eliminate central services. Many organizations use a hosted Git platform as the authoritative collaboration point while developers retain complete local repositories.

DimensionCentralized VCSDistributed VCS
Main historyPrimarily on a serverPresent in each full clone
Offline commitsOften limitedNormally supported
CollaborationCentral server-mediatedRepository exchange plus hosting services
Local history operationsMay require networkUsually local and fast
Typical governanceCentral authorityCanonical remotes and policy controls

7. Git’s Conceptual Model

Git can be understood through three areas:

  1. Working tree: Files being edited.
  2. Staging area (index): The proposed content for the next commit.
  3. Repository: The permanent recorded history.

A typical workflow moves content through these areas:

Edit files → inspect changes → stage selected changes → commit → share with a remote

The staging area is significant because it allows a developer to construct a coherent commit from a larger set of working-tree changes. For example, a developer may fix a bug and improve formatting in the same session but stage only the bug fix for one commit and the formatting for another.

Git stores content in objects commonly described as blobs, trees, commits, and annotated tags. A blob represents file content; a tree represents directory structure and references content; a commit identifies a project state and its parent relationship; a tag can add a human-meaningful name and metadata. This content-addressed design helps Git detect identical content and supports integrity checking.

Git does not automatically understand whether a change is semantically correct. It records content and relationships. Quality still depends on review, testing, secure development practices, and competent judgment.

8. Branches, Merging, and Collaboration

A branch is a movable reference to a line of development. Creating a branch does not normally duplicate the entire project. It provides an independent name under which new commits can be recorded.

Branches support:

  • Isolated feature development.
  • Maintenance of released versions.
  • Experiments that should not disturb the main line.
  • Parallel work by multiple contributors.

When two branches change related content, a merge combines their histories. If Git cannot determine a safe result automatically, it reports a merge conflict. A conflict is not a system failure; it is a request for a human decision about the intended combined content.

Professional teams should keep branches understandable, limit unnecessary long-lived divergence, and require review before changes enter protected release branches. The exact branching strategy—feature branches, trunk-based development, or another model—should match team size, release frequency, risk, and automation maturity.

9. Git in DevOps and Digital Transformation

DevOps emphasizes collaboration between development and operations, automation, rapid feedback, and reliable delivery. Git contributes to these aims by making desired system states explicit and reviewable.

In a typical delivery flow:

  1. A requirement is recorded in a planning system.
  2. A developer creates a branch and changes source or configuration.
  3. The change is committed and reviewed.
  4. A continuous-integration system checks out the revision.
  5. Automated tests, security checks, and quality analysis run.
  6. A build artifact is created and associated with the source revision.
  7. A deployment system promotes the artifact through environments.
  8. Monitoring and operational feedback inform subsequent changes.

This flow is sometimes described as “everything as code.” Infrastructure, deployment configuration, policy, and pipeline definitions can be versioned alongside application code. Version control therefore becomes a mechanism for managing organizational change, not merely a developer tool.

Digital transformation often requires replacing informal, person-dependent processes with transparent and repeatable workflows. Git supports this transformation when paired with automated testing, continuous integration, infrastructure as code, access controls, and useful operational metrics. Git alone cannot transform an organization; it provides a foundation on which disciplined practices can be built.

10. Applied Case: A Small Online Retailer

Background

An illustrative online retailer operates a web application maintained by four developers and one operations engineer. Before adopting Git, the team exchanged compressed project folders and stored deployment files on individual computers.

Problem

A payment defect appeared after a release. The team could not determine which source files had been deployed, who had approved the change, or how to restore the previous working state. Two developers had also edited the same configuration file, and one edit had silently replaced the other.

Analysis

The main weakness was not simply the absence of a particular tool. The team lacked a common source of truth, identifiable revisions, review practices, and a repeatable deployment link between source and production. Backups existed, but they did not provide useful change history.

Approach and solution

The team created a Git repository and adopted the following practices:

  • The main branch represented releasable source.
  • Work was performed on short-lived branches.
  • Each change was reviewed before merging.
  • Commit messages referenced a work item identifier.
  • A continuous-integration pipeline ran tests and security checks.
  • Release tags identified approved versions.
  • Deployment records stored the commit identifier and build artifact identifier.
  • Secrets were removed from the repository and supplied through a secure secret-management service.

Outcome

When a later payment regression occurred, the team identified the deployed tag, compared it with the preceding release, located the relevant commit, and restored the known-good artifact while preparing a fix. The investigation took hours rather than days. The repository also improved onboarding because new staff could understand both current code and its evolution.

Learning points

  1. Version control is most valuable when connected to review, testing, and deployment.
  2. A tag identifies a release, but a complete release record should also identify the built artifact and deployment environment.
  3. Traceability depends on team conventions as well as repository technology.
  4. Sensitive data should not be committed merely because a repository is access-controlled.

11. Challenges, Governance, and Best Practices

Common challenges

Beginners may confuse local and remote repositories, commit too many unrelated changes together, or rewrite shared history without understanding the consequences. Large binary files may make repositories inefficient, while generated files can obscure meaningful source changes. Poorly managed branches can create difficult merges and delayed integration.

Security and governance

Repositories can contain credentials, private keys, personal data, proprietary algorithms, or regulated information. Access should follow least privilege, and protected branches should require appropriate review. Secrets should be stored in dedicated secret-management systems. If a secret is committed, deleting the visible line is not always sufficient: the value may remain in historical commits, clones, caches, or build logs. It must be revoked or rotated, and the incident should be assessed.

Organizations should define retention, ownership, contribution, review, and archival policies. Where software supports safety, finance, healthcare, or other regulated activities, audit evidence should be reliable and access should be controlled. Governance should preserve engineering speed while ensuring that important changes are authorized and reproducible.

Practical best practices

  • Commit small, coherent, working changes where practical.
  • Write messages that explain intent.
  • Review diffs before committing and before merging.
  • Keep generated artifacts and secrets out of source history unless there is a justified policy.
  • Use tags or another release-identification method.
  • Automate tests and quality checks.
  • Back up important repositories and test restoration.
  • Protect important branches and define approval rules.
  • Document the team’s branching and release conventions.
  • Treat repository access as a security responsibility.

12. Contemporary Developments

Modern Git platforms increasingly integrate code review, issue management, continuous integration, security scanning, package registries, and deployment controls. Supply-chain security has increased attention on signed commits, signed tags, provenance records, dependency auditing, and reproducible builds.

Artificial intelligence can assist with commit-message suggestions, code review, test generation, and repository search. These capabilities require human oversight. AI-generated code may introduce licensing, security, privacy, or correctness problems, and its provenance should be considered where organizational policy requires it. Version control remains important because it records proposed changes, enables review, and provides an auditable path for accepting or rejecting machine-assisted work.

Chapter Summary

Version control is a disciplined method for recording and managing successive states of digital artifacts. It reduces the risks of lost work, conflicting changes, unclear releases, and weak accountability. A repository stores history; a revision or commit identifies a recorded state; a snapshot represents project content at a point in time; and a diff explains the change between states.

Centralized systems rely primarily on a central server, whereas distributed systems such as Git provide full repository history in each clone while still supporting authoritative hosted remotes. Git’s working tree, staging area, commits, branches, and merge graph support local experimentation and collaborative delivery. Its greatest DevOps value arises when source history is connected to review, automated testing, build artifacts, deployment records, and monitoring.

Effective use of Git also requires governance. Teams must protect secrets, control access, review important changes, identify releases, preserve traceability, and maintain backups. Git is therefore both a technical tool and an organizational mechanism for making change visible, repeatable, and recoverable.

Key Terms

Version control: A system for recording, comparing, coordinating, and restoring successive states of digital artifacts.

Version-control system (VCS): Software and associated practices used to manage versions and change history.

Repository: A data structure that stores project history, objects, references, and metadata.

Working tree: The checked-out files available for editing.

Revision: An identifiable recorded state or update in project history.

Snapshot: A conceptual representation of project content at a particular point in time.

Diff: A representation of differences between two states.

Commit: A recorded Git change set with metadata and parent relationship.

Commit message: Text explaining the intent or purpose of a commit.

Branch: A named, movable reference to a line of development.

Tag: A named reference commonly used to identify a release or important revision.

Merge: An operation that combines histories from different lines of development.

Conflict: A situation in which intended content cannot be combined automatically.

Staging area: Git’s proposed-content area for the next commit.

Remote repository: A repository used to exchange history with a local repository.

Clone: A repository copy containing project history and configuration for local use.

Traceability: The ability to follow relationships among requirements, changes, tests, artifacts, and deployments.

Centralized version control: A model in which the principal repository history is maintained on a central server.

Distributed version control: A model in which each full clone normally contains repository history.

Continuous integration: The frequent automated integration and validation of changes.

Review Questions

5 Short Answer Questions

  1. What is the primary purpose of version control?
  2. Distinguish a snapshot from a diff.
  3. What information can a useful commit message provide?
  4. What is the difference between a branch and a tag?
  5. Name two advantages of distributed version control.

5 Long Answer Questions

  1. Explain how version control reduces the risks associated with uncontrolled change.
  2. Compare centralized and distributed version-control models, including their advantages and limitations.
  3. Describe Git’s working tree, staging area, and repository, and explain how content moves among them.
  4. Explain how traceability connects source changes with testing and deployment in a DevOps environment.
  5. Discuss the security and governance responsibilities associated with repositories.

3 Analytical / Application Questions

  1. A team has a repository but still deploys manually from developers’ laptops. Analyze which traceability gaps remain and propose controls to close them.
  2. Two developers have modified the same configuration file on separate branches. Explain how a conflict may arise and propose a safe resolution process.
  3. A password was committed to a private repository and then deleted in the next commit. Assess the risk and recommend the correct response.

Multiple Choice Questions with Answers

Question 1

Which statement best defines version control?

A. A method for recording and managing successive states of digital artifacts

B. A process for automatically writing software without developers

C. A backup method that never records change history

D. A technique used only to compress source-code files

Correct Answer: A. A method for recording and managing successive states of digital artifacts

Question 2

What does a snapshot conceptually represent in Git?

A. Only the lines changed since the previous commit

B. The project content at a particular recorded point in time

C. A temporary copy that cannot be restored

D. A list of users authorized to access a repository

Correct Answer: B. The project content at a particular recorded point in time

Question 3

Which item normally identifies the intent of a recorded Git change?

A. File extension

B. Commit message

C. Operating-system kernel

D. Network address

Correct Answer: B. Commit message

Question 4

What is a principal characteristic of distributed version control?

A. Only the central server contains project history

B. Every operation requires an internet connection

C. A full clone normally contains repository history

D. Branches cannot be created locally

Correct Answer: C. A full clone normally contains repository history

Question 5

What is the main purpose of Git’s staging area?

A. To select and prepare content for the next commit

B. To permanently deploy files to production

C. To store passwords securely

D. To replace the repository’s commit history

Correct Answer: A. To select and prepare content for the next commit

Question 6

Which practice most directly improves release traceability?

A. Renaming files with increasingly long names

B. Using release tags and recording the deployed revision

C. Deleting old commits after every deployment

D. Allowing production changes without review

Correct Answer: B. Using release tags and recording the deployed revision

Question 7

What happens when Git cannot automatically combine changes from two branches?

A. A merge conflict is reported for human resolution

B. The repository is automatically erased

C. Both changes are guaranteed to be preserved without review

D. The branch names are converted into tags

Correct Answer: A. A merge conflict is reported for human resolution

Question 8

Which statement about a Git branch is correct?

A. It is always a permanent copy of every file

B. It is a named, movable reference to a line of development

C. It can identify only a deleted commit

D. It is the same thing as a backup archive

Correct Answer: B. It is a named, movable reference to a line of development

Question 9

A password is committed to a repository and deleted in the next commit. What should the team do first?

A. Assume deletion makes the password safe

B. Rename the repository and take no further action

C. Revoke or rotate the password and investigate repository exposure

D. Publish the password in documentation for transparency

Correct Answer: C. Revoke or rotate the password and investigate repository exposure

Question 10

Which sequence best reflects a controlled DevOps change flow?

A. Deploy, edit production, then record an informal note

B. Commit, review, test, build, and deploy an identified revision

C. Copy files between laptops and delete previous versions

D. Test only after a release has been removed

Correct Answer: B. Commit, review, test, build, and deploy an identified revision

Git & Version Control
Chapter 1 of 14