A neat little tool to make cloning of git repos a little more tidy.
Go to file
Masayuki Matsuki 719b543464
Merge pull request #462 from x-motemen/dependabot/github_actions/crate-ci/typos-1.44.0
chore(deps): bump crate-ci/typos from 1.43.4 to 1.44.0
2026-03-17 10:33:53 +09:00
.github Merge pull request #462 from x-motemen/dependabot/github_actions/crate-ci/typos-1.44.0 2026-03-17 10:33:53 +09:00
cmdutil migrate io/ioutil 2022-05-02 22:53:04 +09:00
logger chore: exec go fix ./... 2026-02-15 19:45:03 +09:00
misc Update zsh completion to match current commands and flags 2026-03-03 16:24:46 +09:00
.gitignore Add coverage.out to .gitignore and remove from tracking 2026-02-14 16:05:38 +09:00
.tagpr release as draft by tagpr to hide it before uploading assets 2023-02-23 00:53:33 +09:00
CHANGELOG.md [tagpr] update CHANGELOG.md 2026-02-17 07:40:37 +00:00
cmd_create.go Append ".git" to directory name for bare git repositories 2023-04-04 16:01:11 +08:00
cmd_create_test.go Support pijul 2024-02-02 06:07:34 +09:00
cmd_get.go feat: add partial option support to ghq get 2025-03-26 00:25:03 +09:00
cmd_get_test.go feat: add partial option support to ghq get 2025-03-26 00:25:03 +09:00
cmd_list.go Append ".git" to directory name for bare git repositories 2023-04-04 16:01:11 +08:00
cmd_list_test.go Use t.Cleanup to set environment variables in tests 2022-05-08 10:26:15 +09:00
cmd_migrate.go Fix worktree migration path handling on Windows 2026-02-17 07:30:11 +00:00
cmd_migrate_test.go Fix Windows worktree test by normalizing path separators 2026-02-17 06:54:43 +00:00
cmd_rm.go ghq rm to support bare option 2024-04-04 11:28:15 +09:00
cmd_rm_test.go feat: add unit test 2024-01-26 17:24:59 +09:00
cmd_root.go adjustment 2023-02-24 13:42:09 +08:00
cmd_root_test.go skip a test on windows 2023-02-22 20:42:28 +09:00
codecov.yml introduce codecov 2023-02-22 21:32:40 +09:00
commands.go Format code with goimports and go fmt 2026-02-13 17:01:03 +00:00
commands_test.go feat: add partial option support to GitBackend 2025-03-26 00:24:42 +09:00
CREDITS update deps 2026-02-01 18:07:43 +09:00
getter.go chore: exec go fix ./... 2026-02-15 19:45:03 +09:00
getter_test.go Remove trailing slash before stripping .git from the end 2020-06-29 23:51:09 +09:00
go.mod chore(deps): bump golang.org/x/text from 0.34.0 to 0.35.0 2026-03-16 09:39:50 +00:00
go.sum chore(deps): bump golang.org/x/text from 0.34.0 to 0.35.0 2026-03-16 09:39:50 +00:00
go_import.go Clone URLs by copying net.URL struct 2020-10-30 23:04:30 +01:00
go_import_test.go skip go-import mod 2019-05-12 15:14:56 +09:00
helpers_test.go chore: exec go fmt ./... 2025-03-26 17:18:06 +09:00
helpers_unix.go add windows symlink & junction support 2024-10-27 00:19:49 +09:00
helpers_windows.go add windows symlink & junction support 2024-10-27 00:19:49 +09:00
helpers_windows_test.go add windows symlink & junction support 2024-10-27 00:19:49 +09:00
LICENSE MIT license 2014-06-10 16:31:57 +09:00
local_repository.go chore: exec go fix ./... 2026-02-15 19:45:03 +09:00
local_repository_test.go Append ".git" to directory name for bare git repositories 2023-04-04 16:01:11 +08:00
main.go [tagpr] prepare for the next release 2026-02-17 07:40:36 +00:00
main_test.go fix test 2020-01-04 19:24:08 +09:00
Makefile update deps 2024-11-09 12:33:55 +09:00
README.adoc Add migrate command documentation to README.adoc 2026-02-14 07:13:26 +00:00
remote_repository.go refine git vcs backend detection 2024-11-09 15:40:25 +09:00
remote_repository_test.go Support pijul 2024-02-02 06:07:34 +09:00
typos.toml Add spell check workflow 2023-02-22 15:35:22 +08:00
url.go Revert "feat: enable relative path ssh URL" 2024-04-10 15:46:23 +09:00
url_test.go Revert "feat: enable relative path ssh URL" 2024-04-10 15:46:23 +09:00
vcs.go chore: exec go fix ./... 2026-02-15 19:45:03 +09:00
vcs_test.go feat: add partial option support to GitBackend 2025-03-26 00:24:42 +09:00

= ghq(1) image:https://github.com/x-motemen/ghq/workflows/test/badge.svg?branch=master["Build Status", link="https://github.com/x-motemen/ghq/actions?workflow=test"] image:https://codecov.io/gh/x-motemen/ghq/branch/master/graph/badge.svg["Coverage", link="https://codecov.io/gh/x-motemen/ghq"]

== NAME

ghq - Manage remote repository clones

== DESCRIPTION

'ghq' provides a way to organize remote repository clones, like +go get+ does. When you clone a remote repository by +ghq get+, ghq makes a directory under a specific root directory (by default +~/ghq+) using the remote repository URL's host and path.

    $ ghq get https://github.com/x-motemen/ghq
    # Runs `git clone https://github.com/x-motemen/ghq ~/ghq/github.com/x-motemen/ghq`

You can also list local repositories (+ghq list+).

== SYNOPSIS

[verse]
ghq get [-u] [-p] [--shallow] [--vcs <vcs>] [--look] [--silent] [--branch] [--no-recursive] [--bare] [--partial blobless|treeless] <repository URL>|<host>/<user>/<project>|<user>/<project>|<project>
ghq list [-p] [-e] [<query>]
ghq create [--vcs <vcs>] <repository URL>|<host>/<user>/<project>|<user>/<project>|<project>
ghq rm [--dry-run] <repository URL>|<host>/<user>/<project>|<user>/<project>|<project>
ghq migrate [-y] [--dry-run] <local repository path>
ghq root [--all]

== COMMANDS

get::
    Clone a remote repository under ghq root directory (see
    <<directory-structures,DIRECTORY STRUCTURES>> below). `ghq clone` is an alias for this command.
    If the repository is
    already cloned to local, nothing will happen unless '-u' ('--update')
    flag is supplied, in which case the local repository is updated ('git pull --ff-only' eg.).
    When you use '-p' option, the repository is cloned via SSH protocol. +
    If there are multiple +ghq.root+ s, existing local clones are searched
    first. Then a new repository clone is created under the primary root if
    none is found. +
    With '--shallow' option, a "shallow clone" will be performed (for Git
    repositories only, 'git clone --depth 1 ...' eg.). Be careful that a
    shallow-cloned repository cannot be pushed to remote.
    Currently Git and Mercurial repositories are supported. +
    With '--branch' option, you can clone the repository with specified
    branch. This option is currently supported for Git, Mercurial,
    Subversion and git-svn. +
    The 'ghq' gets the git repository recursively by default. +
    We can prevent it with '--no-recursive' option.
    With '--bare' option, a "bare clone" will be performed (for Git
    repositories only, 'git clone --bare ...' eg.). +
    With '--partial' option, a "partial clone" will be performed (for Git
    repositories only, in 'blobless' mode, 'git clone --filter=blob:none ...',
    in 'treeless' mode, 'git clone --filter=tree:0 ...' eg.).

list::
    List locally cloned repositories. If a query argument is given, only
    repositories whose names contain that query text are listed. '-e'
    ('--exact') forces the match to be an exact one (i.e. the query equals to
    _project_, _user_/_project_ or _host_/_user_/_project_)
    If '-p' ('--full-path') is given, the full paths to the repository root are
    printed instead of relative ones.

root::
    Prints repositories' root (i.e. `ghq.root`). Without '--all' option, the
    primary one is shown.

rm::
    Remove local repository. If '--dry-run' option is given, the repository is not actually removed but the path to it is printed.

create::
    Creates new repository.

migrate::
    Migrate an existing repository directory to the ghq-managed directory structure.
    The command detects the VCS backend, retrieves the remote URL, and moves
    the repository to the appropriate location under ghq root.

== CONFIGURATION

Configuration uses 'git-config' variables.

ghq.root::
    The path to directory under which cloned repositories are placed. See
    <<directory-structures,DIRECTORY STRUCTURES>> below. Defaults to +~/ghq+. +
    This variable can have multiple values. If so, the last one becomes
    primary one i.e. new repository clones are always created under it. You may
    want to specify "$GOPATH/src" as a secondary root (environment variables
    should be expanded.)

ghq.user::
    In ghq, when specifying only the repository name without slashes as in `ghq get {{Project}}`,
    ghq attempts to auto-complete the repository owner.
    By default, the owner used is the value of the environment variable `USER` (or `USERNAME` on Windows).
    Setting this option allows you to explicitly specify the owner.

ghq.completeUser::
    Rather than always using your own username for owner completion,
    you may want to complete the owner with the same name as the repository.
    For example, fetch `ruby` as `github.com/ruby/ruby`,
    `vim` as `github.com/vim/vim`, and `peco` as `github.com/peco/peco`.
    If you prefer this behavior, set this option to `false` to switch the owner completion method.

ghq.<url>.vcs::
    ghq tries to detect the remote repository's VCS backend for non-"github.com"
    repositories.  With this option you can explicitly specify the VCS for the
    remote repository. The URL is matched against '<url>' using 'git config --get-urlmatch'. +
    Accepted values are "git", "github" (an alias for "git"), "subversion",
    "svn" (an alias for "subversion"), "git-svn", "mercurial", "hg" (an alias for "mercurial"),
    "darcs", "fossil", "bazaar", and "bzr" (an alias for "bazaar"). +
    To get this configuration variable effective, you will need Git 1.8.5 or higher.

ghq.<url>.root::
    The "ghq" tries to detect the remote repository-specific root directory. With this option,
    you can specify a repository-specific root directory instead of the common ghq root directory. +
    The URL is matched against '<url>' using 'git config --get-urlmatch'.


=== Example configuration (.gitconfig):

....
[ghq "https://git.example.com/repos/"]
vcs = git
root = ~/myproj
....

== ENVIRONMENT VARIABLES

GHQ_ROOT::
    If set to a path, this value is used as the only root directory regardless
    of other existing ghq.root settings.

== [[directory-structures]]DIRECTORY STRUCTURES

Local repositories are placed under 'ghq.root' with named github.com/_user_/_repo_.

....
~/ghq
|-- code.google.com/
|   `-- p/
|       `-- vim/
`-- github.com/
    |-- google/
    |   `-- go-github/
    |-- motemen/
    |   `-- ghq/
    `-- urfave/
        `-- cli/
....


== [[installing]]INSTALLATION

=== macOS

----
brew install ghq
----

=== Void Linux

----
xbps-install -S ghq
----

=== GNU Guix

----
guix install ghq
----

=== Windows + scoop

----
scoop install ghq
----


=== go get

----
go install github.com/x-motemen/ghq@latest
----

=== conda

----
conda install -c conda-forge go-ghq
----

=== https://github.com/asdf-vm/asdf[asdf-vm]

----
asdf plugin add ghq
asdf install ghq latest
----

=== https://github.com/jdx/mise[mise-en-place]

----
mise install ghq
mise use ghq
----

=== build

----
git clone https://github.com/x-motemen/ghq .
make install
----

Built binaries are available from GitHub Releases.
https://github.com/x-motemen/ghq/releases

== HANDBOOK

You can buy "ghq-handbook" from Leanpub for more detailed usage.

https://leanpub.com/ghq-handbook

The source Markdown files of this book are also available for free from the following repository.

https://github.com/Songmu/ghq-handbook

Currently, only Japanese version available.
Your translations are welcome!

== AUTHOR

* motemen <motemen@gmail.com>
** https://github.com/sponsors/motemen
* Songmu <y.songmu@gmail.com>
** https://github.com/sponsors/Songmu