Version Control with Git and GitHub/GitLab

Chapter 7
Professional Collaboration Workflows

Diploma in DevOps
Version Control with Git and GitHub/GitLab   •   Diploma

Professional Collaboration Workflows

Introduction

Version control becomes a professional collaboration system when it coordinates people, code, review, testing, release, and accountability. A branching workflow is not merely a set of Git commands. It is an agreement about where work occurs, how changes are reviewed, when code is integrated, who may release it, and how defects are corrected.

In a small team, an informal feature-branch practice may be sufficient. In a regulated enterprise, the workflow may need protected branches, mandatory approvals, automated evidence, separation of duties, and traceability from a requirement to a production deployment. DevOps teams therefore select workflows according to delivery frequency, risk, team size, architecture, compliance obligations, and deployment capability.

This chapter examines feature branching, Gitflow, GitHub Flow, GitLab Flow, trunk-based development, and forking workflows. It also explains how these approaches can be combined with pull requests or merge requests, continuous integration, release automation, and branch protection.

Learning Objectives

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

  • explain the purpose of collaboration workflows and the role of branches;
  • apply feature branching and pull-request or merge-request practices;
  • describe and compare Gitflow, GitHub Flow, GitLab Flow, trunk-based development, and forking;
  • evaluate workflow trade-offs involving integration frequency, release control, risk, and operational complexity;
  • select and justify a workflow for a team and delivery context;
  • design governance rules that support quality without creating unnecessary bureaucracy.

1. A Workflow as a Socio-Technical System

A collaboration workflow connects technical activities with human responsibilities. Its principal elements are:

  1. Integration location: the branch into which completed work is merged.
  2. Change isolation: the mechanism used to prevent unfinished work from destabilising shared code.
  3. Review boundary: the point at which peers inspect a change.
  4. Quality gate: automated or manual checks required before integration.
  5. Release path: the route from integrated code to a deployable or deployed system.
  6. Recovery mechanism: rollback, revert, hotfix, or forward-fix procedures.
  7. Ownership and permissions: rules determining who can merge, release, or administer repositories.

A branch is a movable reference to a commit. Creating a branch is inexpensive, but maintaining many long-lived branches creates coordination costs. A workflow must therefore balance isolation against integration. Isolation reduces interference while work is incomplete; integration exposes conflicts and incompatibilities early.

A useful professional principle is that a branch should have a clear purpose and a predictable lifetime. A short-lived branch normally represents one coherent change. A long-lived branch should exist only when it represents a genuine product or operational state, such as a supported release line.

Core terminology

  • Trunk: the principal shared development branch, often named main.
  • Feature branch: a temporary branch for one feature, defect, or small technical change.
  • Release branch: a branch used to stabilise or maintain a particular release.
  • Hotfix branch: a short-lived branch for an urgent production correction.
  • Pull request (PR): a GitHub term for a proposed change and its review conversation.
  • Merge request (MR): the equivalent term commonly used by GitLab.
  • Protected branch: a branch with restrictions on direct pushes, deletion, or merging.
  • Fast-forward merge: a merge in which the target reference can move directly to a descendant commit.
  • Merge commit: a commit with two or more parents, recording the joining of histories.
  • Rebase: the replay of commits on a different base, creating new commit identities.
  • Continuous integration (CI): frequent integration supported by automated build and test execution.
  • Continuous delivery: keeping software in a releasable state through automation and disciplined change management.
  • Continuous deployment: automatically deploying qualifying changes to production.

2. Feature Branching and Collaborative Integration

Feature branching is a general pattern rather than one complete named methodology. Developers create a branch from an agreed base, implement a focused change, push it to the shared repository, and open a PR or MR. Automated checks and peer review occur before the branch is merged.

A typical sequence is:

main ──●────●────────●────────●────
             \                ↑
feature       ●──●──●──●── PR ┘

The branch should be based on a current target branch where practical. The developer should keep the change small, commit logically, run local tests, publish the branch, and explain the purpose, design, testing evidence, and operational effects in the PR or MR. Reviewers should assess correctness, maintainability, security, test adequacy, and compatibility rather than merely formatting.

A professional merge policy commonly requires:

  • successful build and test pipelines;
  • at least one appropriate reviewer;
  • resolution of review conversations;
  • no unresolved merge conflict;
  • a linked issue, change request, or work item when traceability is required;
  • branch protection preventing unauthorised direct changes.

Merge, squash, and rebase choices

A team may preserve every branch commit with a merge commit, combine a branch into one squash commit, or rebase before merging. These choices affect history rather than the functional content of a successful change.

  • Merge commit preserves the branch structure and can show when a contribution was integrated.
  • Squash merge produces a concise target-branch history, useful when development commits are numerous or experimental.
  • Rebase and fast-forward creates a linear history, but because rebasing rewrites commit identities, it should not be used casually on commits already shared by others.

No strategy is universally superior. The important requirements are consistency, recoverability, clear contribution records, and a team understanding of the chosen policy.

3. Gitflow

Gitflow separates development, release preparation, and production support through several branch types. Its classic structure includes:

  • main: the production or released history;
  • develop: the integration branch for upcoming work;
  • feature/*: branches created from and merged into develop;
  • release/*: temporary branches for stabilisation and release preparation;
  • hotfix/*: urgent corrections based on main, normally merged into both main and develop.

The conceptual flow is:

feature/* → develop → release/* → main
                         ↘       ↘
                          develop  tag
main → hotfix/* ───────────────→ main and develop

Gitflow can be useful when a product has scheduled releases, formal stabilisation periods, multiple supported versions, or a large amount of work that must be coordinated before release. A release branch permits documentation, final testing, and low-risk fixes without accepting unrelated features.

Its disadvantages are significant for modern continuous delivery. Multiple long-lived branches increase merge conflicts, duplicate testing, and the chance that develop differs materially from production. Developers may receive feedback late, and the process can encourage large batches of work. Gitflow is therefore generally a poor default for a small team deploying many times per day, unless the team has a special need for its release structure.

Gitflow is a policy pattern, not a requirement to use every branch exactly as originally described. Organisations often simplify it by removing develop, shortening release branches, or using tags and deployment environments instead of persistent release branches.

4. GitHub Flow

GitHub Flow is a lightweight workflow centred on one continuously maintained principal branch, normally main:

  1. create a short-lived branch from main;
  2. make and push small commits;
  3. open a PR early enough for discussion;
  4. allow CI and review to provide evidence;
  5. merge when acceptance conditions are satisfied;
  6. deploy, often automatically, and monitor the result;
  7. delete the branch after integration.

The workflow assumes that main is kept deployable or close to deployable. Feature flags can hide incomplete functionality while allowing code to integrate. A separate release branch is usually unnecessary because release is treated as a deployment decision rather than a prolonged branch phase.

GitHub Flow fits web products and services with frequent releases, strong CI, and a team comfortable integrating small changes. It is less complete as a model for products that must maintain several old versions or undergo long, regulated release approvals. Those needs can be addressed with tags, release branches, environments, approvals, and documented controls without abandoning the basic flow.

5. GitLab Flow

GitLab Flow combines the simplicity of feature branches with explicit relationships between development, testing, staging, and production. Variants may use environment branches such as staging and production, or release branches for supported versions. The exact model should be stated clearly because “GitLab Flow” describes a family of practices rather than one rigid topology.

In an environment-branch model, a change may move through a controlled path:

feature branch → main → staging → production

In a release-branch model, a stable line may be created for a release while ongoing development continues elsewhere. GitLab Flow is useful when deployment environments have different approval requirements, when operations must validate changes before production, or when issue tracking and deployment evidence are integrated into the platform.

The principal risk is confusing an environment branch with the actual deployed state. A branch should not be treated as proof that deployment succeeded. Deployment systems should record commit identifiers, artifacts, approvals, configuration, and health results. Where possible, immutable artifacts should be promoted between environments rather than rebuilt differently for each environment.

6. Trunk-Based Development

Trunk-based development integrates work into the trunk frequently. Developers either commit directly under strong safeguards or use very short-lived branches and merge them quickly. The trunk remains the primary integration point.

It depends on technical discipline:

  • fast, reliable automated tests;
  • small changes;
  • backward-compatible interfaces where possible;
  • feature flags or branch-by-abstraction for incomplete work;
  • rapid correction or rollback of faulty changes;
  • observability sufficient to detect production effects.

A feature flag separates code integration from feature exposure. For example, code for a new payment method may be merged disabled, tested in production-like conditions, and enabled for a controlled group later. Flags must have owners, expiry dates, and removal plans; otherwise they become permanent complexity.

Trunk-based development reduces branch divergence and integration delay. It can improve delivery flow, but it does not eliminate risk. A fast merge into trunk without adequate tests or review simply moves risk into the shared branch. It is inappropriate when the team cannot maintain quality gates or when a product genuinely requires independent long-term release lines.

7. Forking Workflows

In a forking workflow, contributors work in separate repository copies called forks. A contributor pushes to the fork and opens a PR or MR from the fork into the upstream repository. The upstream project controls its branches and permissions.

Forking is particularly valuable for open-source projects, external suppliers, contractors, and teams that should not receive write access to the central repository. It establishes a security boundary and allows the upstream maintainers to review all incoming changes.

The costs include synchronising the fork with upstream, managing contributor identity and permissions, and resolving conflicts when contributions are based on old code. A fork is not automatically a branch strategy: an organisation may use GitHub Flow or Gitflow inside the upstream repository while accepting contributions through forks.

Contributors should avoid exposing secrets in fork pipelines. CI for untrusted code must be designed so that untrusted jobs cannot access privileged deployment credentials. Maintainers should also verify dependencies, review workflow-file changes, and consider whether automated jobs execute code supplied by the contributor.

8. Comparative Evaluation

WorkflowIntegration patternStrengthsMain costs or risksAppropriate context
Feature branchingShort-lived branches into a shared baseFamiliar, reviewable, adaptableBranches can become long-livedMost collaborative teams
GitflowSeparate development, release, and hotfix linesScheduled releases and multiple support linesBranch divergence and process overheadFormal release cycles
GitHub FlowShort-lived branches into mainSimple, fast, deployment-orientedRequires reliable CI and release disciplineFrequently deployed services
GitLab FlowBranches mapped to environments or releasesConnects code, environments, and controlsCan confuse branch state with deployment stateEnvironment-based delivery
Trunk-based developmentVery frequent integration into trunkEarly feedback and low divergenceDemands strong automation and flagsHigh-performing CI/CD teams
ForkingContributions arrive from repository copiesStrong permission boundary and opennessSynchronisation and security complexityOpen source and external contributors

Decision criteria

A team should evaluate at least the following questions:

  • How often must the system be released?
  • Can automated tests complete quickly enough to support frequent integration?
  • Are multiple production versions supported simultaneously?
  • Is there a regulatory or contractual approval path?
  • Do contributors require repository write access?
  • Can unfinished functionality be hidden safely?
  • How costly are merge conflicts in the technology and architecture?
  • What recovery time is acceptable after a faulty change?
  • Which branch should represent the deployable truth?

A useful selection rule is to choose the simplest workflow that satisfies real delivery and governance constraints. Complexity should be justified by a requirement, not inherited from a popular diagram.

9. Applying Governance Without Blocking Delivery

Governance should control material risks while preserving flow. Effective controls include:

  • protected principal and release branches;
  • mandatory status checks;
  • CODEOWNERS or equivalent ownership rules for sensitive components;
  • least-privilege repository permissions;
  • signed commits or verified identities where provenance matters;
  • secret scanning and dependency scanning;
  • audit logs for approvals, merges, and deployments;
  • documented emergency-change procedures;
  • reproducible builds and retained artifacts;
  • separation of duties for high-risk production changes.

A review is not a substitute for testing, and a green pipeline is not proof that a change is correct. Automated checks should cover unit behaviour, integration contracts, security properties, infrastructure validation, and policy requirements in proportion to risk.

Ethically, teams should avoid using workflow controls to conceal responsibility or create a false appearance of safety. Reviewers need sufficient time and context. Automation should not approve changes merely because a metric is green when the change affects safety, privacy, accessibility, or security. Access records and contribution data should be used for legitimate operational purposes and handled according to organisational privacy requirements.

10. Worked Application: Selecting a Workflow

Consider an illustrative company, MetroParcel, operating a parcel-tracking service. Eight developers support a cloud service. The service is deployed several times each week, a small mobile client is released monthly, and the organisation must retain evidence of approvals for security-sensitive changes. It does not maintain old server versions for customers.

A classic Gitflow model would provide release and hotfix branches, but its permanent develop branch and stabilisation cycle would add delay without solving a real requirement for parallel supported versions. Direct trunk commits would reduce review overhead but would not satisfy the organisation’s control expectations.

The selected design is a protected-main GitHub-Flow-like workflow with additional controls:

  1. Each change uses a short-lived branch linked to an issue.
  2. Every change enters through a PR with one code-owner approval for sensitive services.
  3. CI runs tests, static analysis, dependency checks, and infrastructure validation.
  4. main is automatically deployed to a non-production environment.
  5. Production deployment requires an explicit approval and promotes the tested artifact.
  6. Tags identify production releases; a short-lived hotfix branch is permitted for urgent incidents.
  7. Feature flags control incomplete customer-facing capabilities.
  8. Deployment records retain the commit, artifact digest, approver, and outcome.

This design combines the low divergence of GitHub Flow with governance appropriate to the service. The monthly mobile release can use a release branch if the mobile build requires stabilisation, while the server workflow remains continuous. Thus, workflow selection can be component-specific rather than dogmatic.

The outcome should be assessed using operational evidence: lead time for changes, deployment frequency, change failure rate, time to restore service, review delay, and escaped defects. These are indicators, not targets to manipulate. Increasing deployment frequency by weakening tests would not represent improvement.

11. Common Failure Modes and Improvements

Long-lived feature branches. They accumulate conflicts and delay feedback. Reduce scope, integrate incrementally, or use flags.

Unreviewed direct pushes. They weaken accountability and bypass automation. Protect important branches and define an emergency path that is audited afterward.

“Green build” overconfidence. Tests may omit integration, security, or operational failure. Improve test strategy and monitor real deployments.

Branch proliferation. Numerous release, environment, and personal branches obscure the source of truth. Retain only branches with a documented purpose.

Environment drift. Different configuration or manually rebuilt artifacts make results incomparable. Promote the same versioned artifact and manage configuration explicitly.

Stale branches and abandoned flags. Assign owners, use expiry reminders, and remove obsolete assets.

Unsafe fork automation. Untrusted code may access secrets or alter CI definitions. Isolate permissions and require review for privileged workflows.

Inadequate rollback planning. A revert may not undo a database migration or external side effect. Design backward-compatible changes and practise recovery procedures.

12. Contemporary Practice and AI-Assisted Collaboration

Modern repository platforms connect source control with issue tracking, CI/CD, security scanning, environments, and observability. Policy-as-code can enforce branch naming, required checks, dependency rules, and infrastructure standards consistently.

AI-assisted coding and review can generate tests, explain diffs, identify likely defects, and suggest documentation. However, generated code can contain insecure patterns, licensing concerns, hallucinated APIs, or untested assumptions. The author remains responsible for correctness and provenance. AI tools should operate within least-privilege boundaries and must not receive secrets or confidential source without approval. Human review remains essential for security, privacy, architecture, accessibility, and safety implications.

Chapter Summary

Professional collaboration workflows define how teams isolate, review, integrate, release, and recover software changes. Feature branching provides a flexible foundation, while Gitflow adds explicit development, release, and hotfix lines for scheduled or multi-version products. GitHub Flow emphasises short-lived branches and a continuously deployable principal branch. GitLab Flow connects code movement with environments or release lines. Trunk-based development minimises divergence through frequent integration and depends on strong automation, small changes, and feature flags. Forking provides a permission boundary for external contributors and is compatible with other branch strategies.

No workflow is universally best. Selection should follow delivery frequency, testing capability, release structure, governance, security, contributor boundaries, and recovery needs. Effective practice combines a simple branch model with protected branches, automated evidence, review, reproducible artifacts, observability, and explicit accountability.

Key Terms

Branch: A movable reference to a commit history.

Trunk: The principal shared development branch.

Feature branch: A temporary branch for one coherent change.

Pull request: A proposed change submitted for review, especially in GitHub terminology.

Merge request: A proposed change submitted for review, especially in GitLab terminology.

Protected branch: A branch with restrictions on pushing, deleting, or merging.

Gitflow: A branching model with development, release, feature, and hotfix branches.

GitHub Flow: A lightweight workflow using short-lived branches and a principal branch.

GitLab Flow: A family of workflows linking branches with environments or release lines.

Trunk-based development: Frequent integration into the principal shared branch.

Fork: An independent repository copy used for contribution or isolation.

Continuous integration: Frequent integration supported by automated verification.

Feature flag: A runtime control that separates code deployment from feature exposure.

Release branch: A branch used to stabilise or maintain a release line.

Hotfix branch: A short-lived branch for an urgent production correction.

Branch divergence: The accumulation of different commits on related branches.

Merge conflict: A situation requiring human decisions when changes overlap incompatibly.

Code owner: A designated person or group responsible for reviewing specified areas.

Artifact promotion: Moving the same built artifact between environments.

Protected deployment: A deployment requiring specified automated or human controls.

Review Questions

Short Answer Questions

  1. What is the purpose of a feature branch?
  2. Distinguish a pull request from a merge conflict.
  3. Name two assumptions required for effective trunk-based development.
  4. Why are forks useful for open-source contributions?
  5. What problem does a feature flag solve?

Long Answer Questions

  1. Explain Gitflow and evaluate its suitability for a service deployed several times per day.
  2. Compare GitHub Flow and GitLab Flow, including their treatment of environments and releases.
  3. Discuss how branch protection, CI, review, and artifact promotion work together.
  4. Explain the advantages and limitations of trunk-based development.
  5. Describe a governance model for a regulated team that still needs frequent delivery.

Analytical / Application Questions

  1. A team has twelve developers, a six-month release cycle, and three supported customer versions. Select and justify a workflow.
  2. An open-source project receives contributions from unknown external users. Design a safe forking and CI policy.
  3. A team has frequent merge conflicts and a growing number of stale branches. Diagnose the likely workflow problems and propose corrective actions.

Multiple Choice Questions with Answers

Question 1

Which workflow most directly emphasises frequent integration into a shared principal branch?

A. Gitflow

B. Trunk-based development

C. Forking workflow

D. Environment-branch GitLab Flow

Correct Answer: B. Trunk-based development

Question 2

What is the primary purpose of a protected branch?

A. To prevent all branches from being deleted

B. To restrict changes until required controls are satisfied

C. To make every commit a merge commit

D. To automatically deploy every feature

Correct Answer: B. To restrict changes until required controls are satisfied

Question 3

Which Gitflow branch normally represents production or released history?

A. feature

B. develop

C. main

D. staging

Correct Answer: C. main

Question 4

A team wants external contributors to propose changes without giving them write access to the central repository. Which approach is most appropriate?

A. Direct trunk commits

B. A forking workflow

C. Only release branches

D. A local-only repository

Correct Answer: B. A forking workflow

Question 5

What is a principal risk of long-lived feature branches?

A. They eliminate all code review

B. They prevent commits from being created

C. They increase divergence and integration conflicts

D. They automatically expose secrets

Correct Answer: C. They increase divergence and integration conflicts

Question 6

Which practice separates deploying code from making a feature visible to users?

A. Feature flags

B. Fast-forward merging

C. Commit signing

D. Branch deletion

Correct Answer: A. Feature flags

Question 7

In a GitHub-Flow-like process, what normally happens before a short-lived branch is merged?

A. The branch must become a permanent release line

B. Required review and automated checks are completed

C. All other branches are deleted

D. The repository is forked

Correct Answer: B. Required review and automated checks are completed

Question 8

Why should the same artifact preferably be promoted between environments?

A. It guarantees that the code contains no defects

B. It avoids rebuilding different versions for each environment

C. It removes the need for approvals

D. It makes branches unnecessary

Correct Answer: B. It avoids rebuilding different versions for each environment

Question 9

Which situation most strongly supports a classic Gitflow-style model?

A. A service deploying many times daily with no supported old versions

B. A product with scheduled releases and several supported versions

C. A single developer experimenting locally

D. An external contributor with no repository access

Correct Answer: B. A product with scheduled releases and several supported versions

Question 10

What is a major security concern with CI pipelines for untrusted fork contributions?

A. The pipeline may create too many branches

B. Untrusted code may access privileged secrets

C. The contributor cannot write local commits

D. The upstream repository cannot contain tags

Correct Answer: B. Untrusted code may access privileged secrets

Version Control with Git and GitHub/GitLab
Chapter 7 of 14