Diploma in Data science
Getting Started with Git and Version Control
•
Diploma
Collaborative Development Workflows
Introduction
Version control becomes most valuable when several people change the same software, documentation, notebooks, or configuration files. In an individual project, a developer can often commit directly to the default branch. In a team, that practice creates avoidable risks: incomplete work may become visible to users, incompatible changes may be deployed together, and nobody may know who reviewed an important decision.
A collaborative development workflow is an agreed method for organizing branches, commits, reviews, integration, testing, and release. Git provides the technical mechanisms, while platforms such as GitHub and GitLab provide collaboration features including pull requests, merge requests, protected branches, issue tracking, automated checks, and review records.
This chapter examines feature-branch development, GitHub Flow, GitLab Flow, and trunk-based development. It also explains pull and merge requests, code review, branch protection, team conventions, and the professional decisions required to select an appropriate workflow.
Learning Objectives
By the end of this chapter, you should be able to:
Explain why teams use branches and collaborative workflows.
Distinguish feature-branch development, GitHub Flow, GitLab Flow, and trunk-based development.
Create and integrate changes through pull requests or merge requests.
Configure and use protected branches and automated checks.
Establish team conventions that improve consistency and reduce integration risk.
Select a workflow appropriate to a data-science or software project.
1. Collaboration as a Controlled Integration Process
A Git repository contains both a technical history and a record of team decisions. Collaboration is therefore more than exchanging files. It requires a controlled process for answering four questions:
What is being changed? An issue, task, experiment, defect, or enhancement should identify the purpose of the work.
Where is the change made? The team must know which branch or working line contains it.
Who verifies it? Reviewers assess correctness, maintainability, security, and compatibility.
When may it be integrated or released? Automated checks and approval rules provide evidence for this decision.
A branch is a movable reference to a sequence of commits. A feature branch allows a developer to isolate related work from the shared integration branch. Isolation is useful, but it is not an end in itself. Long-lived branches accumulate divergence, increasing the difficulty of integration. The central aim of a collaborative workflow is therefore not to create many branches; it is to integrate safe, understandable changes frequently.
A typical collaborative sequence is:
Select or create an issue describing the work.
Update the local copy of the integration branch.
Create a focused branch.
Make small, coherent commits.
Push the branch to the shared repository.
Open a pull request or merge request.
Run automated checks and obtain review.
Resolve feedback and update the branch.
Merge using the team’s agreed strategy.
Delete the temporary branch and monitor the result.
Collaborative branch and review workflow
Figure: Collaborative branch and review workflow
Figure: A controlled path from a task to an integration branch.
2. Feature-Branch Development
In feature-branch development, each unit of work is performed on a branch created from an integration branch, commonly named main or develop. The branch should represent one coherent purpose, such as feature/add-customer-segmentation or fix/missing-date-validation.
A basic command sequence is:
git switch main
git pull --ff-only
git switch -c feature/add-customer-segmentation
# edit files and run local checks
git add src/ tests/
git commit -m "Add customer segmentation pipeline"
git push -u origin feature/add-customer-segmentation
The option --ff-only prevents Git from silently creating a merge commit when updating the local branch. Teams may choose another update policy, but the important principle is that developers understand how local and remote histories are changed.
A feature branch should be narrow enough to review and test. Combining unrelated refactoring, dependency upgrades, and a new model in one request makes it difficult to identify the source of a failure. Small branches also reduce merge conflicts and allow work to be integrated more frequently.
Feature branches do not automatically make work safe. A branch can still contain sensitive credentials, untested code, large generated files, or changes that break an application. Branching must be combined with meaningful commits, automated checks, review, and repository controls.
Merge Strategies
Platforms commonly support several integration strategies:
Merge commit: The branch history is preserved and a new commit records the integration. This is useful when preserving the exact topology of parallel work matters.
Squash merge: Several branch commits become one commit on the target branch. This creates a concise main-branch history, but may remove useful intermediate detail.
Rebase and merge: The commits are replayed on the current target branch and then integrated without a merge commit. Rewriting commits that other people already use can cause confusion, so teams should define when rebasing is permitted.
No strategy is universally best. The decision should consider audit requirements, release practices, conflict frequency, and the value of preserving intermediate commits.
3. GitHub Flow
GitHub Flow is a lightweight workflow centered on a single continuously releasable default branch, normally main:
Create a descriptive branch from main.
Commit and push incremental work.
Open a pull request early enough for discussion.
Allow automated checks and human review to run.
Merge only when the branch satisfies repository policy.
Deploy or release from main, then monitor the result.
The workflow is especially suitable for web applications, services, libraries, and teams able to deploy frequently. A pull request is both a technical integration mechanism and a communication space. It records the purpose of a change, the evidence supporting it, reviewer comments, and the final decision.
GitHub Flow works best when main is always in a releasable condition. If incomplete work must be merged, teams can use feature flags, configuration switches, or backward-compatible interfaces. A feature flag should have an owner and removal plan; otherwise, temporary controls become permanent complexity.
4. GitLab Flow
GitLab Flow combines the simplicity of feature branches with explicit relationships among development, testing, staging, and production environments. Organizations may use a single main branch with environment branches, or release branches associated with supported versions. The exact model should reflect the organization’s deployment and compliance requirements.
A common environment-oriented flow is:
Changes are developed in a short-lived feature branch.
The change is merged into a development or main branch.
Automated tests and deployment pipelines promote the code to staging.
Acceptance testing occurs in staging.
An approved version is promoted to production.
A release-oriented flow may maintain branches such as release/2.4 for stabilization while new work continues on main. Critical fixes may need to be applied to both the release branch and the main branch. Teams must define how such changes are propagated, because manually repeating a fix can lead to inconsistent implementations.
GitLab Flow is useful where deployment environments, scheduled releases, or regulatory approvals require visible promotion stages. Its additional branches can clarify release management, but they also increase the possibility of divergence. Branches should not be created merely because an organization has multiple environments; automated promotion of the same tested artifact may be safer than rebuilding different code in each environment.
5. Trunk-Based Development
Trunk-based development integrates work into a shared trunk, usually main, very frequently. Developers may commit directly to the trunk in a highly disciplined team, or use very short-lived branches and pull requests. The defining characteristic is the short lifetime of branches and the regular integration of small changes.
This practice reduces the amount of divergent code that must later be reconciled. It demands strong automated tests, rapid feedback, small changes, and careful handling of incomplete functionality. Feature flags, modular design, and backward-compatible database migrations are often important.
Trunk-based development is not the same as allowing unrestricted direct commits. A professional implementation can still require review, status checks, signed commits, or a merge queue. The workflow shifts effort from prolonged branch isolation to continuous integration quality.
Comparing the Workflows
Workflow
Main characteristic
Strength
Main risk
Suitable context
Feature-branch development
Work isolated until integration
Clear separation of tasks
Long-lived branches diverge
General team projects
GitHub Flow
Short branch, pull request, deploy from main
Simple and release-oriented
Assumes main can remain releasable
Web and service teams
GitLab Flow
Branches or stages reflect environments/releases
Visible promotion and release control
More branch-management overhead
Staged or regulated delivery
Trunk-based development
Very frequent integration to trunk
Small integration batches
Requires strong testing and discipline
High-performing continuous-integration teams
These are patterns rather than rigid laws. A team may use short-lived feature branches, protected main, release tags, and staged deployment without adopting every convention of one named model.
6. Pull Requests and Merge Requests
A pull request, commonly used on GitHub, and a merge request, commonly used on GitLab, serve the same broad purpose: proposing that one branch be integrated into another. The terminology differs by platform; the essential practices are similar.
A high-quality request contains:
a concise title describing the change;
a link to the issue or requirement;
a summary of what changed and why;
testing evidence, including commands or pipeline results;
screenshots or output where behavior is visual or data-dependent;
information about migrations, configuration, security, or operational effects;
known limitations and follow-up work.
The target branch must be selected carefully. Merging a production hotfix into an obsolete development branch, for example, can give a false impression that all relevant code contains the fix. Draft requests are useful when early architectural feedback is desired before the work is complete.
A request should be updated rather than closed and recreated for every revision. This preserves the discussion and allows reviewers to see how concerns were addressed. Developers should not rewrite shared history after review without communicating clearly, because comments may no longer refer to the same commits.
7. Code Review as Engineering Practice
Code review is a structured examination of a proposed change by people other than its author. Its purposes include finding defects, improving design, sharing knowledge, checking standards, and identifying operational or security risks. It is not primarily a test of the author’s personal ability.
Reviewers should begin with the change’s purpose and acceptance criteria. They should then examine:
Correctness: Does the implementation satisfy the requirement, including edge cases?
Tests: Do tests demonstrate expected behavior and failure conditions? Are tests reliable rather than merely increasing a coverage percentage?
Data and reproducibility: For data-science work, are input versions, preprocessing steps, random seeds where appropriate, evaluation splits, and metrics documented?
Security and privacy: Does the change expose credentials, personal data, unsafe file access, or injection vulnerabilities?
Maintainability: Are names, interfaces, dependencies, and documentation understandable?
Performance and operations: Could the change create unacceptable cost, latency, memory use, or monitoring gaps?
Compatibility: Does it preserve public interfaces, schemas, and expected behavior for existing users?
Review comments should be specific and respectful. A useful comment identifies the concern, explains its impact, and, when possible, suggests a direction. Reviewers should distinguish blocking defects from optional improvements. Labels such as “must fix,” “suggestion,” and “question” can reduce ambiguity, although written explanation remains necessary.
Authors should treat review as collaborative reasoning. They may disagree with a comment, but should respond with evidence and explain the design choice. Approval should mean that the reviewer has examined the change sufficiently under the team’s policy, not that the reviewer guarantees perfection.
Review Size and Risk
A small request is generally easier to understand than a large request containing unrelated edits. Review size should nevertheless be judged by risk, not only by line count. A one-line change to authentication or a database migration may deserve more scrutiny than a large mechanical rename. Teams can use ownership rules to require review from maintainers of affected components, while avoiding an approval system in which every minor change waits indefinitely for a large committee.
8. Protected Branches and Repository Governance
A protected branch is a branch subject to repository rules. Common controls include:
requiring a pull or merge request;
requiring one or more approvals;
requiring successful automated checks;
requiring the branch to be current with its target before merging;
preventing force-pushes and deletion;
restricting who may merge or push;
requiring signed commits or verified identities where appropriate;
requiring all conversations to be resolved;
enforcing code-owner review for sensitive areas.
Protection should support quality rather than become an obstacle. For example, requiring three approvals for every documentation correction may waste time, while allowing direct pushes to production configuration may create unacceptable risk. Rules should be proportional to the impact of the repository and reviewed as the team changes.
Branch protection is not a substitute for access management. Repository permissions should follow least privilege: each person receives the access needed for their role and no more. Secrets should be stored in an approved secret-management system or protected CI/CD variables, never in source code or review comments. If a secret is committed, deleting the file is insufficient; the secret must be revoked or rotated because it remains in repository history and may exist in clones or caches.
9. Team Conventions
A workflow becomes reliable when its conventions are explicit. A small CONTRIBUTING.md file can define:
branch naming, such as feature/, fix/, and docs/ prefixes;
commit-message style and whether issue identifiers are required;
formatting, linting, testing, and documentation expectations;
the definition of “ready for review”;
required reviewers and ownership rules;
merge strategy and branch-deletion policy;
how urgent fixes, release branches, and reversions are handled;
how data, model artifacts, notebooks, and generated files are managed.
Conventions should be automated where possible. Formatters and linters reduce subjective comments. Continuous integration can run unit tests, static analysis, dependency checks, notebook validation, and data-quality tests. Automation should produce actionable results and should be maintained like production code.
For data-science repositories, teams should distinguish source code from generated outputs. Large datasets and model binaries may belong in object storage or a data/model versioning system rather than ordinary Git history. A repository should document dataset provenance, licensing, privacy constraints, and the procedure for reproducing results. A model that performs well but cannot be reproduced or audited may not be professionally acceptable.
10. Applied Case: An Illustrative Customer-Churn Project
Background
A four-person data-science team is developing a customer-churn prediction service. The repository contains Python code, tests, a feature-engineering notebook, deployment configuration, and documentation. The team previously committed directly to main. A preprocessing change then altered the definition of “active customer,” and the production model and dashboard used different definitions.
Problem
The team needs a workflow that provides review, reproducibility, and controlled deployment without making a small project excessively bureaucratic. It also needs to protect customer data and prevent credentials from entering the repository.
Analysis
The project has a production service and regular deployment needs, so GitHub Flow with short-lived branches is appropriate. The team decides that main must remain deployable, while staging deployment and model validation occur automatically. The team does not store customer records in Git. Synthetic test data represents expected data shapes and edge cases.
Approach and Solution
The team adopts the following policy:
Work begins with an issue describing the business and technical acceptance criteria.
A branch such as feature/define-active-customer is created from updated main.
The pull request must include a description of the old and new definitions.
CI runs formatting, unit tests, data-schema tests, and a reproducibility check on synthetic data.
A code owner reviews feature engineering and a second team member reviews deployment effects.
main is protected against direct pushes and force-pushes.
At least one approval and all required checks are needed for merging.
The pipeline deploys the merged commit to staging; production deployment requires an explicit authorized action.
Model metrics are compared with a documented baseline, but no single metric is treated as sufficient evidence of fairness or fitness.
Secrets are supplied through protected CI variables and rotated according to organizational policy.
The developer opens the pull request before final polishing. A reviewer notices that the new feature uses a timestamp from after the prediction date, creating target leakage. The author corrects the feature and adds a test ensuring that future information is excluded.
Outcome
The revised change is reviewed, tested, and promoted through staging before production. The repository now records why the definition changed, how it was tested, and who approved it. The team spends slightly more time before merging but avoids a silent discrepancy between the model and dashboard.
Learning Points
The case demonstrates that a workflow is a socio-technical control system. Branches isolate work, pull requests create a decision record, CI supplies repeatable evidence, protected branches enforce minimum policy, and domain review detects errors that automated tests may miss. In data science, reproducibility, privacy, leakage prevention, and responsible model evaluation are part of code quality.
11. Challenges and Limitations
Merge conflicts
Conflicts occur when Git cannot automatically reconcile changes. They are resolved by understanding the intended behavior, not by choosing one side mechanically. After resolution, relevant tests must be rerun. Frequent conflicts may indicate branches that are too long-lived, files that contain too many unrelated responsibilities, or unclear ownership.
Review bottlenecks
A workflow can fail socially when a small number of reviewers become a queue. Teams can distribute ownership, define review service expectations, use automated checks for routine rules, and make requests smaller. Approval requirements should be risk-based.
False confidence from automation
A green pipeline proves only that configured checks passed. It does not prove that the requirement is correct, that the tests represent real users, or that the deployment is safe. Human review, monitoring, rollback plans, and post-release evaluation remain necessary.
Branch and process complexity
Too many permanent branches can create uncertainty about which branch is authoritative. Environment branches may drift from production, and release branches may receive fixes that are not propagated elsewhere. Teams should prefer the simplest workflow that meets delivery, safety, and compliance requirements.
Ethical and governance concerns
Collaboration systems record identities, comments, approvals, and sometimes sensitive issue information. Organizations should limit access, retain records according to policy, and avoid placing personal or confidential data in public repositories. For machine-learning projects, review should include data rights, privacy, bias, explainability, and monitoring obligations. A technically successful merge can still be unacceptable if it violates law, contract, or professional standards.
12. Contemporary Practices and Professional Guidance
Modern platforms increasingly provide merge queues, ephemeral preview environments, dependency update automation, security scanning, and policy-as-code. These features can improve reliability when their outputs are understood and maintained. Automated dependency updates should be reviewed for compatibility and security rather than merged blindly.
AI-assisted coding can generate tests, summaries, or implementation suggestions, but generated code requires the same review as human-written code. Teams should consider licensing, confidential prompts, insecure patterns, fabricated APIs, and unverified tests. An AI-generated explanation is not evidence that a change is correct. The repository’s tests, documentation, and human accountability remain essential.
A mature team periodically examines its workflow using questions such as:
How long do branches remain open?
How often do changes fail after integration?
How long does review take?
Are reversions and hotfixes straightforward?
Do checks detect important defects, or only easy formatting errors?
Can a new team member reproduce the project from documented instructions?
These questions support improvement without turning every workflow decision into a rigid performance target.
Chapter Summary
Collaborative development workflows organize how teams propose, review, test, integrate, and release changes. Feature branches isolate focused work, while GitHub Flow emphasizes short-lived branches and a continuously releasable main. GitLab Flow makes environments or release stages explicit, and trunk-based development minimizes branch lifetime through frequent integration. Pull and merge requests create both an integration mechanism and a durable record of technical discussion.
Effective code review examines correctness, tests, security, maintainability, compatibility, operations, and—especially in data science—reproducibility, data provenance, leakage, and privacy. Protected branches enforce minimum quality and authorization rules, but they must be proportionate to risk. Team conventions, automation, least-privilege access, secret management, and clear ownership convert informal habits into dependable practice. No workflow eliminates defects; the appropriate workflow reduces integration risk while preserving the team’s ability to deliver and learn.
Key Terms
Branch: A movable Git reference that identifies a line of commits.
Code review: Structured examination of a proposed change by one or more people other than its author.
Continuous integration: Frequent integration of changes supported by automated build and test checks.
Feature branch: A branch used to isolate a focused unit of work.
Feature flag: A runtime control that enables or disables functionality independently of deployment.
GitHub Flow: A lightweight workflow using short-lived branches, pull requests, and a releasable main branch.
GitLab Flow: A family of workflows connecting branches with environments, releases, or promotion stages.
Integration branch: The branch into which collaborative work is combined.
Merge conflict: A situation in which Git cannot automatically reconcile competing changes.
Merge request: GitLab’s term for a proposed branch integration and its review process.
Protected branch: A branch governed by rules limiting direct pushes, merges, or history rewriting.
Pull request: GitHub’s term for a proposed branch integration and its review process.
Rebase: Replaying commits onto a different base commit, which may rewrite commit identifiers.
Release branch: A branch used to stabilize or maintain a particular release line.
Squash merge: Combining several branch commits into one commit during integration.
Trunk-based development: Frequent integration into a shared trunk using direct commits or very short-lived branches.
Code owner: A designated maintainer or group responsible for reviewing particular repository areas.
Target branch: The branch that will receive the proposed changes.
Review Questions
Short Answer Questions
What is the main purpose of a feature branch?
How does a pull request support collaboration beyond merely merging code?
State two common rules that can be applied to a protected branch.
What distinguishes trunk-based development from a long-lived feature-branch model?
Why should secrets not be stored in a Git repository, even if the file is later deleted?
Long Answer Questions
Compare GitHub Flow and GitLab Flow in terms of branching, deployment stages, strengths, and risks.
Explain how a team should conduct a high-quality code review, including the responsibilities of the author and reviewer.
Discuss the advantages and limitations of merge commits, squash merges, and rebasing.
Design a set of team conventions for a small data-science repository containing code, notebooks, tests, and model artifacts.
Explain why protected branches, automated checks, and human review should be used together rather than treated as substitutes for one another.
Analytical / Application Questions
A team’s feature branches remain open for six weeks and frequently produce conflicts. Analyze the likely causes and propose workflow changes.
A model pull request passes all unit tests but uses information from after the prediction date. Explain why the pipeline passed and design review or testing controls to detect the problem.
An organization maintains separate development, staging, and production branches, but fixes are often applied to only one branch. Evaluate the risk and recommend a safer integration and release approach.
Multiple Choice Questions with Answers
Question 1
Which practice best characterizes trunk-based development?
A. Maintaining a permanent branch for every feature
B. Integrating small changes into a shared trunk frequently
C. Allowing only quarterly integration into production
D. Avoiding automated tests because branches are short-lived
Correct Answer: B. Integrating small changes into a shared trunk frequently
Question 2
What is the primary purpose of a pull request or merge request?
A. To permanently store secret credentials
B. To replace all automated testing
C. To propose, discuss, review, and integrate a branch change
D. To create a new remote repository automatically
Correct Answer: C. To propose, discuss, review, and integrate a branch change
Question 3
Which control prevents a user from directly pushing to a protected branch?
A. A branch-protection rule
B. A commit message prefix
C. A local text editor
D. A feature flag
Correct Answer: A. A branch-protection rule
Question 4
Which merge strategy combines several branch commits into one commit on the target branch?
A. Fast checkout
B. Squash merge
C. Remote tracking
D. Issue linking
Correct Answer: B. Squash merge
Question 5
A reviewer finds that a feature uses data generated after the prediction time. What problem has most likely occurred?
A. Target leakage
B. Branch deletion
C. Commit signing
D. Syntax formatting
Correct Answer: A. Target leakage
Question 6
Which workflow most explicitly connects development with environment or release promotion stages?
A. GitLab Flow
B. A detached HEAD workflow
C. A local-only workflow
D. A documentation-only workflow
Correct Answer: A. GitLab Flow
Question 7
Why should a feature branch generally represent one focused purpose?
A. It makes unrelated changes harder to review and test
B. It prevents Git from recording commits
C. It guarantees that no merge conflict can occur
D. It removes the need for branch protection
Correct Answer: A. It makes unrelated changes harder to review and test
Question 8
What is the correct response when a committed credential is discovered?
A. Rename the file and leave the credential active
B. Delete only the latest working-copy version
C. Rotate or revoke the credential and investigate its exposure
D. Add the credential to the README for transparency
Correct Answer: C. Rotate or revoke the credential and investigate its exposure
Question 9
Which statement about a green CI pipeline is most accurate?
A. It proves that the software meets every business requirement
B. It proves only that the configured checks passed
C. It makes code review unnecessary
D. It guarantees that deployment will have no operational risk
Correct Answer: B. It proves only that the configured checks passed
Question 10
Which review comment is most constructive?
A. “This is bad.”
B. “Rewrite everything.”
C. “This query may expose personal data; can you restrict the selected fields and add a privacy test?”
D. “I approve, but do not inspect the change.”
Correct Answer: C. “This query may expose personal data; can you restrict the selected fields and add a privacy test?”
Getting Started with Git and Version Control
Chapter 7
of 14