LinuxCommandLibrary

hub-init

Initialize a new Git repository with GitHub

TLDR

Initialize a new local repository

$ hub init
copy

SYNOPSIS

hub init [-g|--git-init] [-f|--fetch-upstream-from-origin] [-q|--quiet] [NAME]

PARAMETERS

-g, --git-init
    Always run git init; skip existing repo check

-f, --fetch-upstream-from-origin
    Add 'upstream' remote to GitHub upstream repo

-q, --quiet
    Suppress output for quiet operation

NAME
    Repository name (defaults to current dir); creates dir if missing

DESCRIPTION

The hub init command creates a new Git repository enhanced with GitHub-specific configurations. Unlike plain git init, it optionally sets up a remote named 'origin' pointing to a GitHub repository, prepares OAuth token configuration from $HUB_TOKEN or ~/.config/hub, and enables hub's extended features like pull request creation from the CLI.

It defaults to using the current directory name as the repository name on GitHub but accepts a custom NAME. If the directory doesn't exist, it creates one. This streamlines workflows for GitHub users by bridging Git and GitHub seamlessly.

Ideal for starting projects directly tied to GitHub remotes, it checks for existing repos unless forced, making it safe for incremental use.

CAVEATS

Requires hub installed and GitHub auth (token). Now deprecated; use gh repo create instead. Fails if no GitHub access.

EXAMPLES

hub init myproject
hub init -g -f # Force init with upstream

AUTH SETUP

Sets [hub_oauth_token] in .git/config from env or ~/.config/hub. Run hub auth login first.

HISTORY

Introduced in hub (2011) by @mislav for GitHub CLI integration. Actively maintained until 2022, then superseded by official GitHub CLI (gh). Hub repo archived.

SEE ALSO

git(1) init, hub(1), gh(1) repo create

Copied to clipboard