Description
git-fork
is used to create a personal fork of a repository hosted on a forge such as GitLab or GitHub. Creating a personal fork is an idempotent operation, meaning that you can run git-fork
as many times as you like, you will still only end up with a single personal fork of a repository. git-fork can also optionally clone the personal fork (after it has been created) to a local repository on your machine. Finally, git-fork
can also do some lightweight setup of the local repository after is has been cloned, such as setting up a remote pointing to the upstream repository, sync the personal fork with the upstream repository and configuring pre-push hooks.
git-fork requires that a personal access token is set up.
Usage
$ git fork -h usage: git-fork [options] [<URI>] [<NAME>] -u, --username NAME Username on host --reference DIR Same as git clone's flags 'reference-if-able' + 'dissociate' --depth N Same as git clones flag 'depth' --shallow-since DATE Same as git clones flag 'shallow-since' --setup-pre-push-hook Setup a pre-push hook that runs git-jcheck --host HOSTNAME Hostname for the forge --no-clone Just fork the repository, do not clone it --no-remote Do not add an additional git remote --ssh Use the ssh:// protocol when cloning --https Use the https:// protocol when cloning --sync Sync with the upstream repository after successful fork --verbose Turn on verbose output --debug Turn on debugging output --version Print the version of this tool --mercurial Force use of mercurial -h, --help Show this help text
Examples
Create a personal fork of openjdk/jdk and also clone it to a local repository:
$ git fork https://github.com/openjdk/jdk
Create a personal fork openjdk/jdk and use SSH when cloning the personal fork to a local repository (will use git@github.com:<username>/jdk
when cloning the personal fork):
$ git fork https://github.com/openjdk/jdk --ssh
Create a personal fork of openjdk/jdk and when cloning use commits you already have in another local clone of openjdk/jdk:
$ git fork --reference $HOME/git/github.com/openjdk/jdk https://github.com/openjdk/jdk
Create a personal fork openjdk/jdk and when cloning the personal fork only clone the 10 most recent commits (truncate the rest of the history):
$ git fork --depth=10 https://github.com/openjdk/jdk
Create a personal fork openjdk/jdk and run git-sync immediately after cloning:
$ git fork --sync https://github.com/openjdk/jdk
Configuration
Like for all Skara CLI tools you can configure default values for the flags for git-fork
. This can come in handy if you find yourself using git-fork frequently and want a bit less to type at the command-line. You can for example configure the host that git-fork
will use for openjdk/jdk:
$ git config --global 'fork.openjdk/jdk.host' github.com
Using the above you know only have to type git fork openjdk/jdk
when creating a personal fork of the openjdk/jdk repository.
If you prefer to work with multiple local clones of your personal fork (perhaps one clone per patch you are working on?) then you can shorten your clone times by specifying a local repository that always should be referenced when running git fork openjdk/jdk:
$ git config --global 'fork.openjdk/jdk.reference' /path/to/local/clone/of/openjdk/jdk
If you want git-fork to always sync your personal fork after having cloned your personal fork, set fork.sync
to "true":
$ git config --global fork.sync true
Since git-fork
will call git-sync any configuration you have done for git-sync will also apply.
Source
See GitFork.java.