How to back up your Git repositories

Alberto de Murga
4 min readDec 30, 2021

Making backups is important. You don’t want to lose all your information because of a broken device or a stolen account. One proposed solution is the 3–2–1 method (3 copies, at least in 2 different devices, and 1 of them off-site) and you should make at least one full backup every year (that could match the World Backup Day). What to back up is up to you. You can backup your contacts, emails, messages, social networks content… and your code.

Backing up code is a bit tricky question. Most of the people host their code on their computer, probably with Git and maybe on Github. But having one copy is having no copies. You don’t want to depend on Github exclusively for your code, and it is wise to have at least one extra copy. The question is then, how to make that extra copy.

Photo by Siyuan Hu on Unsplash

Pushing to an additional remote

This is the easiest method with less friction, and it will backup both your code and the git commit history. However, it will require a remote git repository hosted somewhere else, like Gitlab, sourcehut or your own. The issue with this method is that it will not provide you with an offline copy of the code.


  • The easiest and fastest method
  • Preserves git commit history


  • Requires an external server
  • Not offline.
$ git remote add backup <remote empty repository>

Use git bundle

This functionality of git is used to make offline transfers without a server in between. Essentially, it will pick up a branch and .pack it. You can then take the bundle and use it as an origin for a new repository. You can even update the bundle and pull from it.


  • Preserves git commit history.
  • Allows updating the bundle to pull changes.
  • Offline.


  • Requires creating a new repository to see the contents.
  • You can easily mess it up when you try to pull changes from the bundle.
# You can also use --all instead of a branch for bundling
# all branches
$ git bundle create…



Alberto de Murga

Software engineer at @bookingcom. I like to make things, and write about what I learn. I am interested in Linux, git, JavaScript and Go, in no particular order.