A git clone copies commits, but most of what an engineering organisation would need to rebuild after a deleted organisation, a destructive insider or a ransomed self-hosted server lives outside git. Issues, pull or merge requests, review comments, wikis, CI/CD settings, branch protection, webhooks, package registries and the identities that drive automation are all platform data. This guide sets out what to back up beyond the code, what Bitbucket, GitHub and GitLab each provide, how to treat backup tokens as non-human identities, and how to prove restores work. It is for DevOps and platform engineering teams. Platforms are listed alphabetically; order is not a ranking. General backup architecture, immutability and the 3-2-1-1-0 rule are covered in the Backup Security and Immutable Backup Guide.
Key takeaways
- A clone is a copy, not a backup. It captures history but not issues, reviews, settings or secrets references, and a developer's laptop clone is neither complete, independent nor tested.
- Platform exports are not backups by design. GitHub says there is no supported, documented way to restore migration archives, and GitLab says you should not use project export files to back up your data.
- Self-hosted servers have their own key material. GitLab's gitlab-secrets.json and Bitbucket Data Center's shared keys and secrets files are excluded from, or separate to, the data backup, and without them encrypted data cannot be read.
- The backup identity is a crown jewel. A token that can read every repository is a full source code exfiltration path; scope it, expire it and monitor it like any privileged non-human identity.
- Only a restore proves a backup. Schedule restore drills into an isolated organisation or instance and measure time to a working build, not time to a completed copy.
Why a clone is not a backup
Git is distributed, so teams often assume that every developer clone is a backup. GitHub's own guidance confirms that a mirror clone captures the repository "including the revision history", but that is all it captures. Four problems remain:
- Coverage: issues, pull requests and their review threads, discussions, project boards, releases, permissions and CI settings are stored in the platform's database, not in git objects.
- Completeness: developer clones hold the branches each person fetched. Git LFS content is usually only the files someone checked out; GitHub's guidance adds a separate
git lfs fetch --allstep for LFS objects. - Independence: clones are often on machines that share credentials with the platform. A compromise or force-push campaign that rewrites history can also propagate to clones on the next fetch.
- Accountability: nobody owns, protects, monitors or restore-tests a laptop clone, so it fails every basic backup control.
The threats are real. Attackers collect from code repositories (MITRE ATT&CK T1213.003 Code Repositories), and destructive actors delete data (T1485 Data Destruction) and target recovery capability (T1490 Inhibit System Recovery). Extortion against source code often pairs theft with deletion of repositories or organisations. For the theft side, see the Source Code Leak Response Playbook.
What to back up beyond code
Use this table as the coverage baseline. The "how" column describes the general mechanism; exact behaviour per platform is in the next section.
| Data | Stored in | Captured by a mirror clone? | How to capture it |
|---|---|---|---|
| Code, branches, tags, history | Git objects | Yes | Mirror clone (git clone --mirror), verified with git fsck |
| Git LFS objects | LFS storage | No, only pointers | git lfs fetch --all against the mirror, or platform backup |
| Wikis | Separate git repository on GitHub and GitLab | No, separate repository | Clone the wiki repository |
| Issues, comments, labels, milestones | Platform database | No | REST or GraphQL API export, or platform backup |
| Pull or merge requests, reviews, approvals | Platform database (refs for heads only) | Partly: some head refs, never review threads | API export, or platform backup |
| CI/CD pipeline definitions | Usually files in the repository | Yes, if in-repo | Mirror clone; back up shared templates repositories too |
| CI/CD settings, variables, environments, runners | Platform database | No | API export of names and settings; values come from the secrets manager |
| Secrets references | Platform (encrypted) | No | Record secret names and scopes; never export values from the platform |
| Branch protection, rulesets, CODEOWNERS enforcement | Platform settings (CODEOWNERS file is in-repo) | Only the file | API export or configuration as code |
| Webhooks, apps, integrations, deploy keys | Platform settings | No | API inventory; recreate credentials on restore rather than restoring old ones |
| Members, teams, permissions | Platform database or identity provider | No | Identity provider groups as source of truth, plus API export |
| Releases, packages, container images | Platform storage or registry | Tags only | Registry backup or rebuild from tagged source with provenance |
Two design rules follow. First, back up secret names and where each one is used, not secret values: GitHub's Actions secrets API lists secrets "without revealing their encrypted values", and values belong in your secrets manager with its own resilience plan (see the Secrets Manager Resilience Guide). Second, move as many settings as you can into configuration as code (for example rulesets and repository settings managed through Terraform or similar), so the backup of a settings repository becomes the backup of the platform configuration.
Platform capabilities
Each platform offers different native tools for its cloud and self-managed editions. The notes below summarise what the vendors' own documentation says, as checked in November 2026.
Bitbucket
- Bitbucket Cloud: repositories can be mirrored with git. Automation for backup can use repository access tokens, or project and workspace access tokens (Premium), which Atlassian describes as tied to a repository, project or workspace rather than a user, with scopes chosen at creation and an optional expiry date. Pull request and comment data is exported through the REST API.
- Bitbucket Data Center: Atlassian states that a backup must capture the home directory (repository data, logs, plugins), the database (pull requests, comments, users, groups and permissions), any Mesh node home directories, and the shared encryption files
shared/keys,shared/securedandsecrets-config.yaml, warning that losing them could stop Bitbucket working properly. Snapshots of the home directory and database must be consistent with each other; Atlassian documents Zero Downtime Backup (using atomic block-level snapshots) and DIY Backup approaches.
GitHub
- GitHub.com and GitHub Enterprise Cloud: GitHub documents mirror clones,
git lfs fetch --allfor LFS objects, cloning wikis, and migration archives through the REST API. GitHub warns that migration archives "do not include all data related to a repository", naming LFS objects, discussions and packages, and that there is no supported, documented way to restore them, so treat them as archives. Issues, pull requests and settings are captured through the REST or GraphQL APIs or through backup tools listed in the GitHub Marketplace. - GitHub Enterprise Server: recent releases document a built-in backup service, managed from the Management Console, that takes full, timestamped snapshots of instance data; the legacy GitHub Enterprise Server Backup Utilities remain documented. GitHub also notes that a high availability replica is not a replacement for backups, because corruption on the primary can replicate.
GitLab
- GitLab self-managed:
sudo gitlab-backup create(Linux package) produces an archive covering the database, repositories, LFS objects, CI/CD artifacts and job logs, package and container registry data, wikis, uploads, snippets, Terraform states, Pages content and Secure Files. It does not include/etc/gitlab/gitlab.rb,/etc/gitlab/gitlab-secrets.json, Redis, server hooks, TLS and SSH keys, or registry data held in object storage. GitLab warns that the secrets file holds the database encryption key and without it encrypted values cannot be decrypted, so back up both configuration files separately and keep them apart from the data archive. - GitLab.com and project export: project export (Maintainer or Owner role) includes repositories, wikis, uploads, LFS, issues and merge requests with comments, but excludes CI/CD variables, job logs and artifacts, webhooks, encrypted tokens, registry images, deploy keys and Secure Files. GitLab states plainly: "You should not use project export files to back up your data." Use a mirror plus API export for GitLab.com projects.
| Platform and edition | Native full-instance backup | Key material to protect separately | Machine credential for scripted backup |
|---|---|---|---|
| Bitbucket Cloud | Mirror plus REST API export | Access token values | Repository, project or workspace access token with read scopes and an expiry date |
| Bitbucket Data Center | Consistent home directory and database snapshots | shared/keys, shared/secured, secrets-config.yaml | Service account on the snapshot host; API token for metadata export |
| GitHub.com / Enterprise Cloud | Mirror plus API export (migration archives as archive only) | GitHub App private key | GitHub App installation token (expires after one hour, can be limited to listed repositories and permissions) |
| GitHub Enterprise Server | Built-in backup service or legacy Backup Utilities | Backup storage and instance encryption material | Management Console administrator; GitHub App for repository-level copies |
| GitLab.com | Mirror plus API export | Token values | Group or project access token with read scopes; deploy token with read_repository for git only |
| GitLab self-managed | gitlab-backup create | gitlab-secrets.json, gitlab.rb | Host service account; access token for any API export |
Backup identity and access
Whatever does the backup, a script, a third-party service or a host job, needs credentials that can read every repository. That makes it one of the most valuable non-human identities in the estate. The GitHub OAuth token breach shows the pattern: attackers stole OAuth tokens that users had granted to two third-party integrations and used them to list and clone private repositories, including one holding a live cloud key. A backup service holding broad repository tokens is the same shape of risk.
- Use non-user identities: prefer GitHub Apps, Bitbucket repository, project or workspace access tokens, and GitLab group or project access tokens or deploy tokens over a personal access token from an engineer, which breaks when they leave and carries all their rights. See GitHub Apps vs Personal Access Tokens vs OAuth Apps and the GitLab Tokens Security Guide.
- Read only, narrowly scoped: grant read access to contents, metadata, issues and pull requests; never write, admin or delete. GitHub installation tokens can be narrowed per request to specific repositories and permissions. GitLab deploy tokens offer
read_repositoryfor git-only copies. - Short-lived where possible: GitHub installation tokens expire after one hour. GitLab deploy tokens do not expire by default, so set an expiry date. Set expiry on Bitbucket access tokens too.
- Separate the write path: the identity that writes to backup storage must not be able to delete or shorten retention, and the identity that can restore into production should be different again and held under privileged access controls. See the Backup Identity Isolation Guide.
- Store and rotate: keep the token or GitHub App private key in a secrets manager, rotate on a schedule and on staff change, and record an owner. See the GitHub App Private Key Security Guide.
- Monitor it: the backup identity should clone at predictable times from predictable addresses. Alert on use outside the window or from new IPs. The GitHub git.clone and archive download events guide explains the GitHub audit events to watch.
Choosing an approach
| Approach | Fits | Trade-offs |
|---|---|---|
| Native instance backup (self-managed) | Bitbucket Data Center, GitHub Enterprise Server, GitLab self-managed | Complete and supported restore; needs off-instance, immutable copies and separate key material handling |
| Scripted mirror plus API export | Small teams, cloud editions, engineering-led organisations | Low cost and transparent; you own coverage gaps, API rate limits and restore tooling |
| Third-party SaaS backup service | Larger estates on cloud editions needing metadata coverage and retention policies | Broad coverage and restore UI; holds a highly privileged token outside your boundary, so assess it as a critical supplier. See the SaaS Backup Buyer's Guide |
Small organisations can usually start with a scheduled mirror and issue export into immutable object storage. Large organisations with hundreds of repositories, regulated retention or self-hosted instances usually need native instance backups or a dedicated service, plus configuration as code.
Restore testing
- Define objectives: set recovery point and recovery time objectives per tier, for example critical product repositories versus archived experiments.
- Restore into isolation: restore into a separate organisation, workspace, group or a test instance with no production webhooks, runners or deploy credentials attached.
- Verify integrity: run
git fsckon restored repositories, compare branch and tag lists and commit hashes with the source, and check LFS objects resolve. - Verify metadata: sample issues, pull or merge request threads and wiki pages; confirm branch protection and rulesets re-apply from configuration as code.
- Rebuild, do not just restore: trigger a pipeline in the restored copy using freshly issued credentials, and measure time to a successful build. Never restore old deploy keys or tokens; issue new ones.
- Self-managed key test: for GitLab and Bitbucket Data Center, confirm the separately stored secrets files restore with the matching backup and that encrypted values (CI variables, tokens) decrypt.
- Record and fix: log duration, gaps and failures, fix them, and repeat at least quarterly for critical repositories and after platform upgrades. The Backup and Recovery Testing Checklist gives a reusable format.
Metrics
- Coverage: percentage of active repositories with a successful backup in the last 24 hours, including wikis and LFS.
- Metadata coverage: percentage of repositories whose issues and pull or merge requests are exported.
- Restore success: percentage of quarterly drills that reach a working build within the RTO.
- Backup token hygiene: days since last rotation and number of backup identities with write or admin scope (target zero).
- Anomalous backup identity use: count of clone events by the backup identity outside its schedule.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | PR.DS-11, RC.RP-03 | Backups created, protected, maintained and tested; integrity verified before restoration |
| NIST SP 800-53 Rev. 5 | CP-9, CP-10 | System backup; system recovery and reconstitution |
| NIST SP 800-53 Rev. 5 | AC-6, IA-5 | Least privilege and authenticator management for backup identities |
| CIS Controls v8.1 | Control 11 Data Recovery | Automated, protected, isolated backups with recovery testing |
| MITRE ATT&CK | T1213.003, T1485, T1490 | Collection from code repositories; data destruction; inhibiting recovery |
Common failure patterns
- Trusting developer clones: no owner, no LFS, no metadata and no restore test, discovered only when the organisation is deleted.
- Using migration archives or project exports as the backup: both vendors say they are incomplete and not a supported backup or restore route.
- Backing up the data but not the keys: a GitLab archive without
gitlab-secrets.json, or Bitbucket Data Center snapshots without the shared keys and secrets files, restores to a system that cannot decrypt its own data. - A personal token as the backup credential: broad rights tied to one engineer, often never rotated, and broken or orphaned when they leave.
- Backup in the same blast radius: copies stored where the same platform admin or cloud account can delete them.
- Restoring old credentials: reinstating deploy keys and tokens from backup after a compromise reintroduces the attacker's access. Rotate them instead, as the GitHub Organisation Compromise Playbook describes.
Practitioner checklist
- Inventory every organisation, workspace, group and self-hosted instance, and the repositories, wikis and LFS stores in each.
- Back up code with mirrors or native instance backups, and metadata (issues, pull or merge requests, settings) through APIs or native backup.
- Store self-managed key material (GitLab secrets and configuration, Bitbucket Data Center shared keys and secrets files) separately and securely.
- Record secret names and usage, not values; keep values in the secrets manager.
- Move branch protection, rulesets and repository settings into configuration as code.
- Run backups with a non-user, read-only, expiring identity, stored in a secrets manager with a named owner.
- Write backups to immutable, separately administered storage outside the source platform's admin domain.
- Alert on backup identity use outside its schedule or source addresses.
- Restore-test quarterly into isolation, through to a working build with freshly issued credentials.
Standards and references
- GitHub Docs: Backing up a repository
- GitHub Docs: Configuring backups on your instance (GitHub Enterprise Server)
- GitLab Docs: Back up GitLab
- GitLab Docs: Migrate projects and groups by using file exports
- Atlassian: Bitbucket Data Center data recovery and backups
- Atlassian: Bitbucket Cloud access tokens
- GitHub Docs: Generating an installation access token for a GitHub App
- GitLab Docs: Deploy tokens
Related NHI Mgmt Group resources: Backup Security and Immutable Backup Guide · Bitbucket Security Guide · GitHub and GitHub Actions Security Guide · GitLab Security Guide · Git Repository Security Guide