{"id":13424925,"url":"https://github.com/amitsaha/gitbackup","last_synced_at":"2026-01-03T07:21:06.779Z","repository":{"id":17752701,"uuid":"71038392","full_name":"amitsaha/gitbackup","owner":"amitsaha","description":"Tool to backup your Bitbucket, GitHub and GitLab repositories","archived":false,"fork":false,"pushed_at":"2025-08-06T23:48:46.000Z","size":17933,"stargazers_count":207,"open_issues_count":13,"forks_count":37,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-08-14T21:36:57.687Z","etag":null,"topics":["backup","bitbucket","git","github","gitlab","golang-application"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amitsaha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-10-16T08:23:06.000Z","updated_at":"2025-08-06T23:47:15.000Z","dependencies_parsed_at":"2025-01-11T08:25:18.990Z","dependency_job_id":"f63549b4-c563-41ba-9a97-48a2f842388e","html_url":"https://github.com/amitsaha/gitbackup","commit_stats":{"total_commits":149,"total_committers":9,"mean_commits":"16.555555555555557","dds":"0.38926174496644295","last_synced_commit":"d7d659a1b38b429f673d70277342fb79e6f6650d"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/amitsaha/gitbackup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitsaha%2Fgitbackup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitsaha%2Fgitbackup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitsaha%2Fgitbackup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitsaha%2Fgitbackup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amitsaha","download_url":"https://codeload.github.com/amitsaha/gitbackup/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitsaha%2Fgitbackup/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270515647,"owners_count":24598436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","bitbucket","git","github","gitlab","golang-application"],"created_at":"2024-07-31T00:01:00.906Z","updated_at":"2026-01-03T07:21:06.772Z","avatar_url":"https://github.com/amitsaha.png","language":"Go","readme":"# gitbackup - Backup your GitHub, GitLab, Bitbucket, and Forgejo repositories\n\nCode Quality [![Go Report Card](https://goreportcard.com/badge/github.com/amitsaha/gitbackup)](https://goreportcard.com/report/github.com/amitsaha/gitbackup)\n[![.github/workflows/ci.yml](https://github.com/amitsaha/gitbackup/actions/workflows/ci.yml/badge.svg)](https://github.com/amitsaha/gitbackup/actions/workflows/ci.yml)\n\n- [gitbackup - Backup your GitHub, GitLab, Bitbucket, and Forgejo repositories](#gitbackup---backup-your-github-gitlab-and-bitbucket-repositories)\n  - [Introduction](#introduction)\n  - [Installing `gitbackup`](#installing-gitbackup)\n  - [Using `gitbackup`](#using-gitbackup)\n    - [GitHub Specific oAuth App Flow](#github-specific-oauth-app-flow)\n    - [OAuth Scopes/Permissions required](#oauth-scopespermissions-required)\n      - [Bitbucket](#bitbucket)\n      - [GitHub](#github)\n      - [GitLab](#gitlab)\n      - [Forgejo](#forgejo)\n    - [Security and credentials](#security-and-credentials)\n    - [Examples](#examples)\n      - [Backing up your GitHub repositories](#backing-up-your-github-repositories)\n      - [Backing up your GitLab repositories](#backing-up-your-gitlab-repositories)\n      - [GitHub Enterprise or custom GitLab installation](#github-enterprise-or-custom-gitlab-installation)\n      - [Backing up your Bitbucket repositories](#backing-up-your-bitbucket-repositories)\n      - [Backing up your Forgejo repositories](#backing-up-your-forgejo-repositories)\n      - [Specifying a backup location](#specifying-a-backup-location)\n      - [Cloning bare repositories](#cloning-bare-repositories)\n      - [GitHub Migrations](#github-migrations)\n  - [Building](#building)\n  \n## Introduction\n\n``gitbackup`` is a tool to backup your git repositories from GitHub (including GitHub enterprise),\nGitLab (including custom GitLab installations), Bitbucket, or Forgejo.\n\n``gitbackup`` currently has two operation modes:\n\n- The first and original operating mode is to create clones of only your git repository. This is supported for GitHub, Gitlab, Bitbucket, and Forgejo.\n- The second operating mode is only available for GitHub where you can create a user migration (including orgs) which you get back as a .tar.gz\n  file containing all the artefacts that GitHub supports via their Migration API.\n  \nIf you are following along my [Linux Journal article](https://www.linuxjournal.com/content/back-github-and-gitlab-repositories-using-golang) (published in 2017), please obtain the version of the \nsource tagged with [lj-0.1](https://github.com/amitsaha/gitbackup/releases/tag/lj-0.1).\n\n## Installing `gitbackup`\n\nBinary releases are available from the [Releases](https://github.com/amitsaha/gitbackup/releases/) page. Please download the binary corresponding to your OS\nand architecture and copy the binary somewhere in your ``$PATH``. It is recommended to rename the binary to `gitbackup` or `gitbackup.exe` (on Windows).\n\nIf you are on MacOS, a community member has created a [Homebrew formula](https://formulae.brew.sh/formula/gitbackup).\n\n## Using `gitbackup`\n\n``gitbackup`` requires a [GitHub API access token](https://github.com/blog/1509-personal-api-tokens) for\nbacking up GitHub repositories, a [GitLab personal access token](https://gitlab.com/profile/personal_access_tokens)\nfor GitLab repositories, a username and [app password](https://bitbucket.org/account/settings/app-passwords/) for\nBitbucket repositories, or a [Forgejo access token][https://docs.codeberg.org/advanced/access-token/] for Forgejo.\n\nYou can supply the tokens to ``gitbackup`` using ``GITHUB_TOKEN``, ``GITLAB_TOKEN``, or ``FORGEJO_TOKEN`` environment\nvariables respectively, and the Bitbucket credentials with ``BITBUCKET_USERNAME`` and ``BITBUCKET_PASSWORD``.\n\n### GitHub Specific oAuth App Flow\n\nStarting with the 0.6 release, if you run `gitbackup` without specifying `GITHUB_TOKEN`, it will prompt you to complete\na oAuth flow to grant the necessary access:\n\n```\n$ ./gitbackup -service github -github.repoType starred\nCopy code: \u003csome code\u003e\nthen open: https://github.com/login/device\n```\nOnce your authorize the app, `gitbackup` will retrieve the token, and also store it in your operating system's\nkeychain/keyring (using the [99designs/keyring](https://github.com/99designs/keyring) package - thanks!). Next\ntime you run it, it will ask you for the keyring password and retrieve the token automatically.\n\n\n### OAuth Scopes/Permissions required\n\n#### Bitbucket\n\nFor the App password, the following permissions are required:\n\n- `Account:Read`\n- `Repositories:Read`\n\n#### GitHub\n\n- `repo`: Reading repositories, including private repositories\n- `user` and `admin:org`: Basically, this gives `gitbackup` a lot of permissions than you may be comfortable with. \n   However, these are required for the user migration and org migration operations.\n\n#### GitLab\n\n- `api`: Grants complete read/write access to the API, including all groups and projects.\nFor some reason, `read_user` and `read_repository` is not sufficient.\n\n#### Forgejo\n\nThe following permissions are required:\n\n- `read:repository`\n- `read:user`\n\n### Security and credentials\n\nWhen you provide the tokens via environment variables, they remain accessible in your shell history \nand via the processes' environment for the lifetime of the process. By default, SSH authentication\nis used to clone your repositories. If `use-https-clone` is specified, private repositories\nare cloned via `https` basic auth and the token provided will be stored  in the repositories' \n`.git/config`.\n\n### Examples\n\nTyping ``-help`` will display the command line options that `gitbackup` recognizes:\n\n```\n$ gitbackup -help\nUsage of ./gitbackup:\n  -backupdir string\n        Backup directory\n  -bare\n        Clone bare repositories\n  -forgejo.repoType string\n        Repo types to backup (user, starred) (default \"user\")\n  -githost.url string\n        DNS of the custom Git host\n  -github.createUserMigration\n        Download user data\n  -github.createUserMigrationRetry\n        Retry creating the GitHub user migration if we get an error (default true)\n  -github.createUserMigrationRetryMax int\n        Number of retries to attempt for creating GitHub user migration (default 5)\n  -github.listUserMigrations\n        List available user migrations\n  -github.namespaceWhitelist string\n        Organizations/Users from where we should clone (separate each value by a comma: 'user1,org2')\n  -github.repoType string\n        Repo types to backup (all, owner, member, starred) (default \"all\")\n  -github.waitForUserMigration\n        Wait for migration to complete (default true)\n  -gitlab.projectMembershipType string\n        Project type to clone (all, owner, member, starred) (default \"all\")\n  -gitlab.projectVisibility string\n        Visibility level of Projects to clone (internal, public, private) (default \"internal\")\n  -ignore-fork\n        Ignore repositories which are forks\n  -ignore-private\n        Ignore private repositories/projects\n  -service string\n        Git Hosted Service Name (github/gitlab/bitbucket/forgejo)\n  -use-https-clone\n        Use HTTPS for cloning instead of SSH\n```\n\n#### Backing up your GitHub repositories\n\nTo backup all your own GitHub repositories to the default backup directory (``$HOME/.gitbackup/``):\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github\n```\n\nTo backup only the GitHub repositories which you are the \"owner\" of:\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github -github.repoType owner\n```\n\nTo backup only the GitHub repositories which you are the \"member\" of:\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github -github.repoType member\n```\n\nSeparately, to backup GitHub repositories you have starred:\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github -github.repoType starred\n```\n\nAdditionally, to backup only the GitHub repositories under 'user1' and 'org3':\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github -github.namespaceWhitelist \"user1,org3\"\n```\n\n#### Backing up your GitLab repositories\n\nTo backup all projects you either own or are a member of which have their [visibility](https://docs.gitlab.com/ce/api/projects.html#project-visibility-level) set to\n\"internal\" on ``https://gitlab.com`` to the default backup directory (``$HOME/.gitbackup/``):\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup -service gitlab\n```\n\nTo backup only the GitLab projects (either you are an owner or member of) which are \"public\"\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup -service gitlab -gitlab.projectVisibility public\n```\n\nTo backup only the private repositories (either you are an owner or member of):\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup -service gitlab -gitlab.projectVisibility private\n```\n\nTo backup public repositories which you are an owner of:\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup \\\n    -service gitlab \\\n    -gitlab.projectVisibility public \\\n    -gitlab.projectMembershipType owner\n```\n\nTo backup public repositories which you are an member of:\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup \\\n    -service gitlab \\\n    -gitlab.projectVisibility public \\\n    -gitlab.projectMembershipType member\n```\n\nTo backup GitLub repositories you have starred:\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup -service gitlab \\\n  -gitlab.projectMembershipType starred \\\n  -gitlab.projectVisibility public\n```\n\n#### GitHub Enterprise or custom GitLab installation\n\nTo specify a custom GitHub enterprise or GitLab location, specify the ``service`` as well as the\nthe ``githost.url`` flag, like so\n\n```lang=bash\n$ GITLAB_TOKEN=secret$token gitbackup -service gitlab -githost.url https://git.yourhost.com\n```\n\n#### Backing up your Bitbucket repositories\n\nTo backup all your Bitbucket repositories to the default backup directory (``$HOME/.gitbackup/``):\n\n```lang=bash\n$ BITBUCKET_USERNAME=username BITBUCKET_PASSWORD=password gitbackup -service bitbucket\n```\n\n#### Backing up your Forgejo repositories\n\nThe `forgejo` service backs up `codeberg.org` by default.\nTo back up all your Codeberg repositories to the default directory (``$HOME/.gitbackup/``):\n\n```lang=bash\n$ FORGEJO_TOKEN=access_token gitbackup -service forgejo\n```\n\nTo back up a different Forgejo instance, specify `githost.url`:\n\n```lang=bash\n$ FORGEJO_TOKEN=access_token gitbackup -service forgejo -githost.url https://git.yourhost.com\n```\n\nTo back up starred repositories instead of those you have access to, specify `forgejo.repoType`:\n\n```lang=bash\n$ FORGEJO_TOKEN=access_token gitbackup -service forgejo -forgejo.repoType starred\n```\n\n#### Specifying a backup location\n\nTo specify a custom backup directory, we can use the ``backupdir`` flag:\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github -backupdir /data/\n```\n\nThis will create a ``github.com`` directory in ``/data`` and backup all your repositories there instead.\nSimilarly, it will create a ``gitlab.com`` directory, if you are backing up repositories from ``gitlab``, a\n``bitbucket.com`` directory if you are backing up from Bitbucket, and a ``codeberg.org`` (or your custom host)\ndirectory if you are backing up from Forgejo.\n\nIf you have specified a Git Host URL, it will create a directory structure ``data/host-url/``.\n\n\n#### Cloning bare repositories\n\nTo clone bare repositories, we can use the ``bare`` flag:\n\n```lang=bash\n$ GITHUB_TOKEN=secret$token gitbackup -service github -bare\n```\n\nThis will create a directory structure like ``github.com/org/repo.git`` containing bare repositories.\n\n#### GitHub Migrations\n\n`gitbackup` starting from the 0.6 release includes support for downloading your user data/organization data as \nmade available via the [Migrations API](https://docs.github.com/en/rest/reference/migrations). As of this\nrelease, you can create an user migration (including your owned organizations data) and download the migration\nartefact using the following command:\n\n```\n$ ./gitbackup -service github -github.createUserMigration -ignore-fork -github.repoType owner\n\n2021/05/14 05:05:27 /home/runner/.gitbackup/github.com doesn't exist, creating it\n2021/05/14 05:05:35 Creating a user migration for 129 repos\n2021/05/14 05:05:46 Waiting for migration state to be exported: 0xc0002a6260\n2021/05/14 05:06:48 Waiting for migration state to be exported: 0xc000290070\n..\n2021/05/14 05:33:44 Waiting for migration state to be exported: 0xc0001c2020\n\n2021/05/14 05:34:46 Downloading file to: /home/runner/.gitbackup/github.com/user-migration-571089.tar.gz\n\n2021/05/14 05:35:00 Creating a org migration (FedoraScientific) for 19 repos\n2021/05/14 05:35:03 Waiting for migration state to be exported: 0xc000144050\n..\n2021/05/14 05:39:05 Downloading file to: /home/runner/.gitbackup/github.com/FedoraScientific-migration-571098.tar.gz\n..\n2021/05/14 05:46:16 Downloading file to: /home/runner/.gitbackup/github.com/practicalgo-migration-571103.tar.gz\n```\nYou can then integrate this with your own scripting to push the data to S3 for example (See an example\nworkflow via scheduled github actions [here](https://github.com/amitsaha/gitbackup/actions/workflows/backup.yml)).\n\n## Building\n\nIf you have Go 1.24.x installed, you can clone the repository and:\n\n```\n$ go build\n```\n\nThe built binary will be ``gitbackup``.\n","funding_links":[],"categories":["Go","Tools"],"sub_categories":["Comparing workflows"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitsaha%2Fgitbackup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famitsaha%2Fgitbackup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitsaha%2Fgitbackup/lists"}