快速克隆或备份大量 org/users 仓库到一个目录 - 支持 GitHub、GitLab、Bitbucket 等
## Supported Providers - GitHub (Self Hosted & Cloud) - [Install](https://github.com/gabrie30/ghorg#installation) | [Setup](https://github.com/gabrie30/ghorg#github-setup) | [Examples](https://github.com/gabrie30/ghorg/blob/master/examples/github.md) - GitLab (Self Hosted & Cloud) - [Install](https://github.com/gabrie30/ghorg#installation) | [Setup](https://github.com/gabrie30/ghorg#gitlab-setup) | [Examples](https://github.com/gabrie30/ghorg/blob/master/examples/gitlab.md) - Bitbucket (Cloud & Self-hosted Server) - [Install](https://github.com/gabrie30/ghorg#installation) | [Setup](https://github.com/gabrie30/ghorg#bitbucket-setup) | [Examples](https://github.com/gabrie30/ghorg/blob/master/examples/bitbucket.md) - Gitea (Self Hosted Only) - [Install](https://github.com/gabrie30/ghorg#installation) | [Setup](https://github.com/gabrie30/ghorg#gitea-setup) | [Examples](https://github.com/gabrie30/ghorg/blob/master/examples/gitea.md) - Codeberg (Cloud & Self Hosted Forgejo) - [Install](https://github.com/gabrie30/ghorg#installation) | [Setup](https://github.com/gabrie30/ghorg#codeberg-setup) | [Examples](https://github.com/gabrie30/ghorg/blob/master/examples/codeberg.md) - Sourcehut (Limited Features) - [Install](https://github.com/gabrie30/ghorg#installation) | [Setup](https://github.com/gabrie30/ghorg#sourcehut-setup) | [Examples](https://github.com/gabrie30/ghorg/blob/master/examples/sourcehut.md) > The terminology used in ghorg is that of GitHub, mainly orgs/repos. GitLab and BitBucket use different terminology. There is a handy chart thanks to GitLab that translates terminology [here](https://about.gitlab.com/images/blogimages/gitlab-terminology.png). Note, some features may be different for certain providers. ## High Level Features - [Filter](#selective-repository-cloning) or select specific repositories for cloning - Create [backups](#creating-backups) of repositories - Simplify complex clone commands using [reclone](#reclone-command) shortcuts - Initiate clone operations via [HTTP server](https://github.com/gabrie30/ghorg/blob/master/examples/reclone-server.md) - Schedule cloning tasks using [cron](https://github.com/gabrie30/ghorg/blob/master/examples/reclone-cron.md) - Monitor and track clone [metrics](#tracking-clone-data-over-time) over time ## Installation There are a installation methods available, please choose the one that suits your fancy: - [Prebuilt Binaries](#prebuilt-binaries) - [Homebrew](#homebrew) - [Mise](#mise) - [Golang](#golang) - [Scoop](#scoop) - [Docker](#docker) For each installation method, optionally create a ghorg configuration file. See the [configuration](#configuration) section for more details. ```bash mkdir -p $HOME/.config/ghorg curl https://raw.githubusercontent.com/gabrie30/ghorg/master/sample-conf.yaml > $HOME/.config/ghorg/conf.yaml vi $HOME/.config/ghorg/conf.yaml # To update your configuration ``` ### Prebuilt Binaries See [latest release](https://github.com/gabrie30/ghorg/releases/latest) to download directly for - Mac (Darwin) - Windows - Linux If you don't know which to choose its likely going to be the x86_64 version for your operating system. ### Homebrew ```bash brew install ghorg ``` ### Mise If you use [Mise](https://github.com/jdx/mise), you can install the latest version of `ghorg` on Linux/MacOS/Windows: ```bash mise use -g ghorg@latest ``` ### Golang Ensure `$HOME/go/bin` is in your path ```bash go install github.com/gabrie30/ghorg@latest ``` ### Scoop Windows users can also install ghorg using [scoop](https://scoop.sh/#/) ``` scoop bucket add main scoop install ghorg ``` ## Configuration Precedence for configuration is first given to the flags set on the command-line, then to what's set in your `$HOME/.config/ghorg/conf.yaml`. This file comes from the [sample-conf.yaml](https://github.com/gabrie30/ghorg/blob/master/sample-conf.yaml) and can be installed by performing the following. ```bash mkdir -p $HOME/.config/ghorg curl https://raw.githubusercontent.com/gabrie30/ghorg/master/sample-conf.yaml > $HOME/.config/ghorg/conf.yaml vi $HOME/.config/ghorg/conf.yaml # To update your configuration ``` If no configuration file is found ghorg will use its defaults and try to clone a GitHub Org, however an api token is always required. You can have multiple configuration files which is useful if you clone from multiple SCM providers with different tokens and settings. Alternative configuration files can only be referenced as a command-line flag `--config`. If you have multiple different orgs/users/configurations to clone see the `ghorg reclone` command as a way to manage them. Note: ghorg will respect the `XDG_CONFIG_HOME` [environment variable](https://wiki.archlinux.org/title/XDG_Base_Directory) if set. ## SCM Provider Setup > Note: if you are running into issues, read the troubleshooting and known issues section below ### GitHub Setup 1. Create [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) with all `repo` scopes. Update `GHORG_GITHUB_TOKEN` in your `ghorg/conf.yaml` or as a cli flag or place it in a file and add the path to `GHORG_GITHUB_TOKEN`. If your org has Saml SSO in front you will need to give your token those permissions as well, see [this doc](https://docs.github.com/en/github/authenticating-to-github/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on). 1. For cloning GitHub Enterprise (self hosted github instances) repos you must set `--base-url` e.g. `ghorg clone --base-url=https://internal.github.com` 1. See [examples/github.md](https://github.com/gabrie30/ghorg/blob/master/examples/github.md) on how to run #### GitHub App Authentication (Advanced) 1. [Create a GitHub App](https://docs.github.com/en/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app) in your Organization. You only need to fill out the required fields. Make sure to give Repository Permissions -> contents -> read only permissions 1. Install the GitHub App into your Organization 1. Generate a a private key from the GitHub App, set the location of the key to `GHORG_GITHUB_APP_PEM_PATH` 1. Locate the GitHub App ID from the GitHub App, set the value to `GHORG_GITHUB_APP_ID` 1. Locate the GitHub Installation ID from the URL of the GitHub app, set the value to `GHORG_GITHUB_APP_INSTALLATION_ID`. NOTE: you will need to use the actual GitHub url to get this ID, go to your GitHub Organization Settings Page -> Third Party Access -> GitHub Apps -> Configure -> Get ID from URL ### GitLab Setup 1. Create [Personal Access Token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) with the `read_api` scope (or `api` for self-managed GitLab older than 12.10). This token can be added to your `ghorg/conf.yaml` or as a cli flag. 1. Update the `GitLab Specific` config in your `ghorg/conf.yaml` or via cli flags or place it in a file and add the path to `GHORG_GITLAB_TOKEN` 1. Update `GHORG_SCM_TYPE` to `gitlab` in your `ghorg/conf.yaml` or via cli flags 1. See [examples/gitlab.md](https://github.com/gabrie30/ghorg/blob/master/examples/gitlab.md) on how to run ### Gitea Setup 1. Create [Access Token](https://docs.gitea.io/en-us/api-usage/) (Settings -> Applications -> Generate Token) 1. Update `GHORG_GITEA_TOKEN` in your `ghorg/conf.yaml` or use the (--token, -t) flag or place it in a file and add the path to `GHORG_GITEA_TOKEN`. 1. Update `GHORG_SCM_TYPE` to `gitea` in your `ghorg/conf.yaml` or via cli flags 1. See [examples/gitea.md](https://github.com/gabrie30/ghorg/blob/master/examples/gitea.md) on how to run ### Codeberg Setup [Codeberg](https://codeberg.org) runs [Forgejo](https://forgejo.org), which is API-compatible with Gitea, so ghorg reuses its Gitea backend and defaults the base URL to `https://codeberg.org` (no `--base-url` required). Self-hosted Forgejo instances are also supported by setting `--base-url`; instances served over http additionally require `--insecure-codeberg-client`. 1. Create an [Access Token](https://codeberg.org/user/settings/applications) (Settings -> Applications -> Generate Token) with at least the `read:organization` and `read:repository` scopes 1. Update `GHORG_CODEBERG_TOKEN` in your `ghorg/conf.yaml` or use the (--token, -t) flag or place it in a file and add the path to `GHORG_CODEBERG_TOKEN`. 1. Update `GHORG_SCM_TYPE` to `codeberg` in your `ghorg/conf.yaml` or via cli flags 1. See [examples/codeberg.md](https://github.com/gabrie30/ghorg/blob/master/examples/codeberg.md) on how to run ### Sourcehut Setup 1. Create a [Personal Access Token](https://meta.sr.ht/oauth2). Click "Limit scope of access grant", check "Generate read-only access token", then ctrl-click the REPOSITORIES and OBJECTS permissions. 1. Ensure you have added an SSH key if you want to clone private repos (sourcehut does not accept PATs in https URLs) 1. Update `GHORG_SOURCEHUT_TOKEN` in your `ghorg/conf.yaml` or use the (--token, -t) flag or place it in a file and add the path to `GHORG_SOURCEHUT_TOKEN`. 1. Update `GHORG_SCM_TYPE` to `sourcehut` in your `ghorg/conf.yaml` or via cli flags > **Note on usernames**: You can specify sourcehut usernames with or without the `~` prefix (e.g., both `ghorg clone username` and `ghorg clone ~username` work). Local folder paths will never include the `~` prefix to avoid shell expansion issues. > **For detailed examples, API limitations, and sourcehut-specific features, see [examples/sourcehut.md](https://github.com/gabrie30/ghorg/blob/master/examples/sourcehut.md)** ### Bitbucket Setup > Note: ghorg supports both Bitbucket Cloud and Bitbucket Server (self-hosted instances) #### API Tokens (Recommended for Bitbucket Cloud) Bitbucket has deprecated App Passwords in favor of API Tokens. This is the recommended authentication method for Bitbucket Cloud. 1. Create an [API token](https://support.atlassian.com/bitbucket-cloud/docs/create-an-api-token/) from your Atlassian account settings 1. **Important**: When creating the token, grant **all read scopes** (Account: Read, Workspace membership: Read, Projects: Read, Repositories: Read, etc.) to ensure ghorg can list and clone repositories 1. Set `GHORG_BITBUCKET_API_TOKEN` in your `$HOME/.config/ghorg/conf.yaml` or use the `--token` flag 1. Set `GHORG_BITBUCKET_API_EMAIL` to your Atlassian account email (or use `--bitbucket-api-email`) 1. Update SCM type to `bitbucket` in your `ghorg/conf.yaml` or via cli flags 1. See [examples/bitbucket.md](https://github.com/gabrie30/ghorg/blob/master/examples/bitbucket.md) on how to run > Note: When using API tokens, ghorg automatically uses `x-bitbucket-api-to
暂无开放 Issues,或尚未同步最近议题。