Create a GitHub Repository with gh repo create
gh repo create can make your new repository public before you have properly decided that it should be. Budget five minutes for a clean empty repository, or ten if you are wiring up an existing local project. Every example below uses this GitHub CLI command.
The route
Jump straight to the step you need, or tick off Done means at the end.
- The
ghexecutable, already authenticated. - Permission to create a repository under the chosen owner or organisation.
1. Check the installed command and sign-in state
This guide was checked against GitHub CLI 2.87.3, released 23 February 2026. Run the version check first: a different gh may support different flags, so read the local help rather than trusting this page blindly.
$ gh --version
gh version 2.87.3 (2026-02-23)
$ gh repo create --help
If authentication is not ready, stop and sign in through your normal GitHub CLI process first. Never put an access token in a shell command, a script or a repository URL. The command itself does not need sudo; elevated privileges are not a substitute for GitHub authorisation.
2. Choose visibility before creating anything
A non-interactive command must include one of --public, --private or --internal. Treat that flag as your safety checkpoint, not an afterthought.
- Public exposes the repository to everyone.
- Private limits access according to GitHub permissions.
- Internal is for an organisation, and is not a general substitute for private.
Check the owner and name too. Omit the OWNER/ part and the command defaults to the authenticating user; an organisation name is not a harmless label, it changes where the repository lives and who can administer it.
To create a public repository and clone it into the current directory:
$ gh repo create example-project --public --clone
This creates the remote and clones it locally in one step. Check your current directory first, because --clone needs a sensible place to put a new directory. Then verify the remote without changing it:
$ git -C example-project remote -v
origin https://github.com/YOUR-ACCOUNT/example-project.git (fetch)
origin https://github.com/YOUR-ACCOUNT/example-project.git (push)
$ gh repo view YOUR-ACCOUNT/example-project
3. Create an empty remote with useful metadata
For an empty repository, add a description, homepage or initial README explicitly. A README changes the remote's contents, so decide first whether your local project should provide the first commit instead.
$ gh repo create YOUR-ACCOUNT/example-project \
--private \
--description "Example project maintained by the team" \
--homepage "https://example.invalid/example-project" \
--add-readme
After creation, check the repository page and its visibility:
$ gh repo view YOUR-ACCOUNT/example-project
$ gh repo view YOUR-ACCOUNT/example-project --json name,visibility,url
Warning
Never put passwords, API keys, private customer data or generated build output into a public repository. The --disable-issues and --disable-wiki flags change the new repository's features; use them only when that policy is intentional.
4. Attach an existing local repository
Use --source when the project already exists on disk. Inspect its status and remotes first: the source directory may hold files you never meant to publish.
$ cd /path/to/YOUR-PROJECT
$ git status --short
$ git log -1 --oneline
$ git remote -v
Review both ignored and tracked files. A secret that is already tracked stays part of the commit history even after you add it to .gitignore. Remove and rotate any exposed credential before you create or push the repository.
Then create a private remote and name the local remote explicitly:
$ gh repo create YOUR-ACCOUNT/example-project \
--private \
--source=. \
--remote=origin
Without a name supplied, the remote repository name comes from the source directory. --remote only sets the local Git remote name; it has no effect on the GitHub owner or repository name.
5. Push local commits only after reviewing them
Creating the remote does not mean every local commit should follow it there. Check the branch, recent commits and remote URL first, then either add --push to the creation command or push through Git afterwards.
$ git branch --show-current
$ git log --oneline -5
$ git remote get-url origin
$ git push --set-upstream origin YOUR-BRANCH
To make gh repo create push while it creates the repository, use the same source workflow with --push:
$ gh repo create YOUR-ACCOUNT/example-project \
--private \
--source=/path/to/YOUR-PROJECT \
--remote=origin \
--push
For a template repository, pass --template OWNER/TEMPLATE, and add --include-all-branches only when every template branch is wanted. A template, like an existing source, is not a clean-room operation: review its files and history before you share it further.
6. Recover from a mistake
There is no undo flag in gh repo create. If the command created the wrong remote, stop before pushing and confirm the repository name and owner in GitHub.
Warning
Repository deletion is irreversible unless you have an independent copy, so treat it as a considered decision, not an automatic cleanup step. Remove an unwanted repository through its GitHub settings only after checking it holds no needed work.
If a push failed, keep the local commits. Check the error, confirm the remote URL, and retry only after verifying visibility and access:
$ git remote -v
$ gh repo view YOUR-ACCOUNT/example-project
$ git push
If the remote ended up with the wrong visibility, change that setting in GitHub after checking who may already have accessed it. If a secret was pushed, rotate it first: changing visibility or deleting a file does not make a leaked credential safe again.
Done means
- Checked the installed GitHub CLI version and authentication state.
- Reviewed the owner, name and visibility before creation.
- Inspected the source tree before pushing any local commits.
- Matched the Git remote and GitHub repository visibility to the intended project.
- Confirmed no secret, private data or unwanted branch was published.