A developer tidies up branches in the product repository and pushes a change with the --force flag. An hour later it turns out that a colleague’s commits from the last three days have disappeared from the server. The commits may still sit in the colleague’s local copy, if they have not overwritten it. But the IT team has no backup from which the company could restore the repository on its own terms.
GitHub backup is the account owner’s job, not the platform provider’s, and the same goes for GitLab. GitHub and GitLab run the service, but the customer is responsible for the account contents, their protection and the ability to restore them. For a company whose product is code, this is a gap in cybersecurity and business continuity as serious as having no backup of a database server.
Do GitHub and GitLab back up your repositories?
Not in the sense an IT team means by a backup: the documentation of both platforms assumes that the customer makes a backup that can be restored at a chosen moment and place. GitHub’s Terms of Service, effective from 27 April 2026, state that the service is provided “as is” and without a warranty that it will be available at any particular time. The same document contains a clause under which GitHub is not liable for loss of data “however arising”, that is, whatever the cause.
GitLab puts it in a similar way, if in different words. Its backup and restore documentation states that data security is ensured for GitLab.com, but the methods described there cannot be used to export or back up your own data from GitLab.com. Those procedures apply to GitLab Self-Managed instances, whose backup is the administrator’s responsibility. The same page explains why to use them: backups safeguard against data loss due to hardware failures, software bugs and accidental deletions, and allow an instance to be restored after an adverse event.
A company with an individual enterprise agreement has to check the liability provisions in its own contract, rather than assume they differ from the standard terms.
How does the shared responsibility model apply to repositories?
The provider is responsible for running the service; the customer is responsible for what it puts in the account, who has access to it and whether it can be recovered. GitHub’s terms spell out the second half: users are responsible for the security of their account and for all content and activity on it, and the content of the account and its security are up to them. GitHub adds that it offers tools such as two-factor authentication, but you have to use them yourself. Multi-factor authentication enforced for every organisation member and a small group of administrators reduce the risk of someone deleting repositories from a compromised account.
In practice, this means the platform will not protect you against many data loss scenarios, because from its point of view nothing has gone wrong. A forced push to an unprotected branch, deletion of a repository by an administrator with the right permissions, a compromised account deleting projects, or closing an organisation are all correctly executed operations by an authorised user. The platform carries them out because that is how it works. It follows that the company’s backup plan must cover repositories too.
What does a repository backup protect against, and what does it not?
A backup protects against data loss for reasons the platform does not react to, or reacts to too late: human error, malicious activity from a compromised account, account closure and service unavailability. Git’s documentation describes the first of these scenarios bluntly. The --force flag of git push disables safety checks and, according to the git-push manual, can cause the remote repository to lose commits.
GitHub provides a limited safety net for deleted repositories. According to its restore documentation, this is possible within 90 days, and a repository from a fork network that is not empty can only be restored by GitHub Support on paid plans; restoring does not bring back team permissions either. After an account is cancelled, GitHub’s terms provide for deleting repository content within 90 days; during that time you can request a copy, and GitHub commits only to a “reasonable effort”.
A repository backup does not, however, protect against code leaks or a malicious commit, which ends up in the backup along with the rest of the history. That is the job of access control, change review and code scanning, described in the article on securing the DevOps environment. A backup ensures that you can return to a known good state.
Key points:
- GitHub’s terms exclude liability for data loss, and GitLab’s backup procedures cannot be used for data on GitLab.com.
- A forced push, a deleted repository and a closed account are valid operations from the platform’s point of view.
- Restoring a deleted repository on GitHub has a 90-day limit and exceptions.
What do you need to back up besides the code?
You need to back up everything the team cannot rebuild its work without: the Git repository, Git LFS objects, the wiki, and platform metadata such as issues, code reviews and CI/CD configuration. A Git repository contains files and the history of changes. Issues, pull requests and merge requests, comments, releases and project settings live in the platform’s database, not in the repository.
GitHub’s documentation lists several layers. Large files stored in Git LFS have to be fetched with a separate git lfs fetch --all command. A GitHub wiki is a separate Git repository that is cloned on its own. Migration archives, which include selected metadata, leave out Git LFS objects, discussions and packages, among other things.
On GitLab, the list of what a project export does not include is longer. According to GitLab’s documentation, items left out of the export include CI/CD variables, webhooks, job traces and artifacts, package and container registry images, and encrypted tokens. If your CI/CD variables hold credentials for your environments, losing them stops deployments even when the code is safe.
Is git clone —mirror enough as a backup?
A mirror clone is enough as a backup of the Git repository with its full history, but not as a backup of the whole project on the platform. GitHub’s documentation on backing up a repository describes exactly the git clone --mirror command, followed by git lfs fetch --all if the repository uses Git LFS. According to the git-clone manual, a mirror clone maps all refs of the source, including remote-tracking branches and notes, not just local branches.
Restoring is simple: you decompress the archive and push the repository to a new remote. That simplicity is the mirror clone’s strength. The backup can be restored on another platform, for example from GitHub to your own GitLab instance, without depending on a provider’s tool.
The limitation is just as clear. A mirror clone contains no issues, code reviews, branch protection settings or CI/CD variables. For a library repository whose history lives in commits, that may be enough. For a product repository where design decisions are recorded in code reviews and deployments depend on variables, it is only part of the backup.
Why is a GitLab project export not a backup?
A project export is meant for migration, and GitLab itself advises against using it as a backup. The project import and export documentation says plainly that you should not use project export files to back up your data, because using them for backups does not always work and not all items are exported.
The same documentation gives two practical reasons for caution. First, export files are stored on the server only temporarily, and a GitLab worker deletes them every 24 hours, so they have to be downloaded and moved straight away. The list of items that are not exported includes those that are hard to rebuild by hand: CI/CD variables, webhooks and encrypted tokens.
GitHub has a similar caveat about migration archives. Its documentation notes that there is no supported, documented way to restore such an archive on GitHub, so it is suitable only for archiving. An archive from which you cannot restore the project does not meet the definition of a backup.
How do you design repository backups: frequency, retention and location?
You design repository backups the same way as any other: from acceptable data loss, through the type and frequency of backups, to retention and a storage location outside the reach of the same account. Frequency follows from how much work the team can afford to lose in a given repository. If the team can lose at most a day’s work, a backup has to run at least once a day; an archived project needs one less often.
The choice between full and incremental backups works here as it does for other data. An incremental backup saves space but lengthens the chain that has to be restored, as discussed in detail in the article on full, incremental and differential backups. The principles of keeping backups in several copies and locations are set out in the guide to backup and the 3-2-1 strategy.
The storage location matters in particular. A backup kept in the same GitHub account or the same GitLab group, accessible to the same administrator account, will fall together with the original if that account is compromised. A backup in separate storage, with separate credentials and, where possible, in immutable mode, as described in the article on immutable backup, is safer.
The backup also has to keep up with the organisation. Teams create new repositories as the product grows, so a mechanism that backs up a list of repositories written down at deployment will, after a few months, miss part of the code. The list of repositories to back up should be generated automatically from the organisation or group account, and the backup report should show the repositories that were not included.
How do you protect the backup itself and access to it?
Protect a repository backup like a production environment, because it contains code, history and may contain credentials. Git history keeps every version of a file, so a password or API key once committed to the repository and later removed is still in the backup. The backup therefore has to be encrypted, and access to it limited to the people who actually restore data.
The backup mechanism should run from a separate technical account with the least privileges it needs, meaning read-only where the platform allows it. That account’s token is a key to all of the company’s code, so store it in a secrets vault, rotate it and monitor its use. An account that can read every repository and also delete backups combines two roles that should be separated.
How do you check that a repository backup can be restored?
You check a backup by restoring it to an empty repository on another instance and comparing the result with the original. The test answers three questions: are all branches and tags present, do the LFS objects download, and can the project be built from the restored code and the restored configuration?
Record the test result together with the time it took. Restoring many repositories along with their CI/CD variables and team permissions is a series of tasks, not a single command. Without a test, nobody knows how long it really takes, and that figure is needed in the disaster recovery plan described in the article on the DRP. Repeat the test after every change of backup tool, platform or organisation structure on the platform, because each of them can quietly change what ends up in the backup.
What does each repository backup method cover?
No single method covers everything, so you choose a set of methods to fit the type of repository and the platform. The table compares the methods described in the providers’ documentation.
| Method | What it covers | What it does not cover | When it is enough |
|---|---|---|---|
git clone --mirror + git lfs fetch --all | All refs, full history, LFS objects | Issues, code reviews, wiki, CI/CD variables, settings | A repository where only code and history matter |
| Wiki repository clone (GitHub) | Wiki pages with history | Everything except the wiki | As a complement to the mirror clone |
| GitHub migration archive | Repository and selected metadata | LFS objects, discussions, packages; no supported restore on GitHub | Archiving, not restoring |
| GitLab project export | Repository, issues, merge requests, comments and other items on the list | CI/CD variables, webhooks, artifacts, registries, encrypted tokens | Migration; GitLab advises against using it as a backup |
| GitLab Self-Managed instance backup | The instance, following GitLab’s procedure | Does not apply to GitLab.com | When the company runs its own instance |
| Third-party backup tool (GitHub points to the Backup Utilities category in GitHub Marketplace) | Depends on the tool | Depends on the tool | When metadata and automated retention are needed; check the scope in the tool’s documentation |
Key points:
- A mirror clone is the foundation of a backup, but it does not cover platform metadata.
- A GitLab project export and a GitHub migration archive do not replace a backup from which you can restore the project.
- A backup is only meaningful once a restore has been tested on another instance.
How can nFlo help with backups of repositories and the rest of the environment?
Repository backups are part of a broader backup and recovery strategy in the company’s IT infrastructure. As part of its Backup and Disaster Recovery service, nFlo carries out a business impact analysis that sets RTO and RPO for each system, designs a backup strategy following the 3-2-1 rule, configures immutable backups, prepares a disaster recovery plan and tests restores.
For other systems, such as workstations, servers, Microsoft 365, Google Workspace and databases, nFlo deploys solutions including Xopero ONE, a Polish cloud backup platform with data centres in Poland. If you want to establish which repositories and systems need which kind of backup and how quickly they must be restored, talk to us.
What else should you know about repository backups?
Will GitHub restore a deleted repository?
Sometimes. According to GitHub’s documentation, a deleted repository can be restored within 90 days unless it was part of a fork network that is not currently empty. Restoring does not bring back team permissions, and support for unusual cases is available only on paid plans. It is a rescue feature, not a backup.
Are clones on developers’ laptops enough as a backup?
No. A clone on a laptop contains only what that developer fetched, has no issues, code reviews or CI configuration, and disappears with the laptop. Nobody checks whether such a collection of clones covers every repository and branch either.
Does GitLab Self-Managed need a separate backup?
Yes. For an instance you run yourself, its administrator performs the backup. GitLab’s documentation describes the instance backup and restore procedures and recommends a recovery plan with regular backups.
How often should you back up repositories?
As often as the acceptable data loss for a given repository requires. A product repository the team works in every day needs a different frequency from an archived project. Set the frequency in the business impact analysis together with other systems.
Can a repository backup contain secrets?
Yes, if anyone ever committed a password, key or token, because Git history keeps every version of a file. That is why the backup has to be protected like a production environment: encrypted, with restricted access and a record of who reads it.
