Copyright (c) 2012 Bart Massey
Note: *The latest version of this package changed the
HOST variable in mkgit customization scripts: it is now
called GITHOST. Please adjust your scripts accordingly.
This tool, based on an idea by Julian Kongslie, creates a
new git repository on an upstream host and pushes the
current repository up to it, setting everything up so that
the upstream host is now being tracked. Both Python (mkgit)
and shell (mkgit.sh) versions are available, with the Python
version being the primary implementation and the shell script
retained for legacy compatibility.
You must have appropriate access (ssh for custom hosts, API tokens for GitHub/GitLab) to create repositories on your target host.
mkgit supports two installation methods:
# Install the main script
sudo cp mkgit.py /usr/local/bin/mkgit
sudo chmod +x /usr/local/bin/mkgit# Install via pip (recommended)
pip install mkgit
# Or install from source
pip install .Site configuration files (see examples/mkgit-big-site and
examples/mkgit-little-site for examples) are searched for in
this order:
- Directory specified by
MKGIT_SITE_DIRenvironment variable /usr/local/share/mkgit/(default)- Same directory as the
mkgitexecutable (fallback)
These files contain variable assignments like:
GITHOST=big-site.example.org
PARENT=/storage/git
REPOLINK=/var/git-links
To use a custom location for site files:
export MKGIT_SITE_DIR=/path/to/my/mkgit-sites
mkgit -X mysite myrepoThe pip install method provides:
- Automatic command installation: Creates
mkgitcommand in PATH - Self-contained: All functionality included in single mkgit.py file
- Easy updates:
pip install --upgrade mkgitfor new versions - Dependency management: Handles Python package requirements
- Platform independence: Works across all platforms consistently
The project uses a single-source layout for easier maintenance:
- mkgit.py: Single source of truth for all functionality
- No src/ directory: Clean root-level package structure
- Both methods work: Copy method and pip install use same code
- PyPI ready: Package builds with
python3 -m buildand uploads with twine
Site configuration files (see examples/mkgit-big-site and
examples/mkgit-little-site for examples) are searched for in
these locations:
- Directory specified by
MKGIT_SITE_DIRenvironment variable /usr/local/share/mkgit/(default)- Same directory as the
mkgitexecutable (fallback)
These files contain variable assignments like:
GITHOST=big-site.example.org
PARENT=/storage/git
REPOLINK=/var/git-links
To use a custom location for site files:
export MKGIT_SITE_DIR=/path/to/my/mkgit-sites
mkgit -X mysite myrepoCreate a GitHub repository:
mkgit -d "My new project" -X github my-projectCreate a private GitLab repository:
mkgit -p -X gitlab my-projectCreate a repository on a custom SSH host:
mkgit ssh://[email protected]/git/storage/my-project.gitFork an existing GitHub repository:
mkgit -F -X githubusage: mkgit [-h] [-p] [-d DESCRIPTION] [-F] [-X SITE] [--list-sites]
[repo] [source_dir]
Create a new upstream git repository
positional arguments:
repo name of repository (with or without .git)
source_dir source directory (defaults to current directory)
options:
-h, --help show help message and exit
-p, --private make new repo private
-d, --description DESCRIPTION
description line for new repo
-F, --fork instead of a new repo, make a new upstream fork
-X, --site SITE site for new repo (use --list-sites for options)
--list-sites list available site optionsgithub- Create repository on github.comgitlab- Create repository on gitlab.comgithub-org- Create repository in specific GitHub organizationgitlab-host-org- Create repository on specific GitLab instance for organizationssh://host/path/repo.git- Create repository via SSH on custom host
Available sites can be listed with --list-sites.
GitHub:
- Create
~/.githubuserwith your username - Create
~/.github-oauthtokenwith GitHub personal access token
GitLab:
- Create
~/.gitlabuser-<host>with your username - Create
~/.gitlabtoken-<host>with GitLab personal access token
Custom SSH: SSH key authentication to target host
-
Public GitHub Repository:
cd my-new-project mkgit -d "Description from first commit" -X github
-
Private GitLab Repository:
cd existing-project mkgit -p -d "Internal project" -X gitlab private-project
-
Custom Host Repository:
cd local-project mkgit ssh://[email protected]/projects/my-project.git
-
Fork GitHub Repository:
cd upstream-project mkgit -F -X github -
Repository in Organization:
cd team-project mkgit -d "Team project" -X github-org myorg
The "magic -X modes" can be customized by putting site variable
definitions in mkgit-<site> scripts in the same directory as
the mkgit executable. See examples/mkgit-big-site and
examples/mkgit-little-site for examples. All of this is fragile
and a bit experimental: patches welcome.
Each site configuration file can set these variables:
GITHOST- Target hostnamePARENT- Parent directory path on targetREPOLINK- Directory for repository symlinks (optional)
Site configuration files must have executable permissions and be in the same
directory as the main mkgit script.
This work is under the "MIT license". See the file LICENSE.txt in the source distribution for license terms.