cli: Known problems with `repo create` command

The gh repo create command right now has separate and potentially confusing behaviors when ran inside an existing local git repository vs. outside of it.

Bugs:

Features:

Ref. https://github.com/cli/cli/pull/547

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 23
  • Comments: 32 (9 by maintainers)

Most upvoted comments

@dhanushkac Yes, running gh repo create inside an existing git repo that has no git remotes is supposed to create the GitHub project for that repo (taking the directory name as the default project name) and add it as the origin remote.

Just for organizational purposes, here are the current designs related to issues listed out here. I can update if these evolve in their respective discussions

Creating a repo with git init, licenses, and gitignore

Screen Shot 2021-01-07 at 9 41 49 AM

gh repo list

Screen Shot 2021-01-07 at 9 40 20 AM

@ardazeytin The PR where --template was added has some additional info: https://github.com/cli/cli/pull/1590

Basically, --team is unsupported because the API endpoint to create a repository from a template doesn’t accept --team. We could theoretically try to make a separate API request to give the team access after the repo has been created, but I’m not sure if that would work with the current permissions model.

You may absolutely open a feature request with this, but note that since it would involve an API change on GitHub, fixing it might take us longer than with features that don’t require any new APIs.

Is it a valid usage that running gh repo create inside existing repo?

@sun: Ah, I didn’t realize some old versions of git don’t have -C. Thanks for letting us know!

@g14a: We marked this issue “core” because the bugs are maybe too gnarly to be taken on by a regular contributor, but you are far from a regular contributor 😉 So go right ahead if you feel confident you can tackle some of the bugs listed above. 🙇

@eacp: Which templates do you mean? But in general yes, we prefer to fetch most data over API instead of storing it. GitHub CLI doesn’t work in offline mode.

ℹ️ If you see the following error with gh repo create then ensure you have the latest version of git installed.

☝️ You might have to add a different package repository for your OS/distribution to retrieve the latest version.

$ gh repo create myorg/myrepo -y --private --enable-issues=false --enable-wiki=false
✓ Created repository myorg/myrepo on GitHub
Initialized empty Git repository in ./myrepo/.git/
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
exit status 129

@eacp Sorry for the late reply!

I think that adding a license and/or gitignore files via a specialized command is a good feature to have in general, not just while creating a new repository. But we need to discuss first with the team to see if we want to greenlight the feature. We’ll update the thread(s) when we decide that this is something we want in core.

Thank you for the feedback!

Hello @ampinsk, this design looks very good. However, I was wondering if we could decouple the generation of files from the gh repo create command, and instead use commands like gh repo license or gh repo ignore in order to keep gh repo more modular. This is just a proposal tho, it looks very good right now.

Given that there are only two actions items left in this tracking issue and:

  • one is intractable
  • the other has no clearly great solution

I’m going to close this. Shout out to @pxrth9 and @meiji163 whose work on rewriting repo create solved a big pile of the command’s issues.

@samcoe It looks like somebody 😆 updated the package in brew… gh --version gh version 2.4.0 (2021-12-21) https://github.com/cli/cli/releases/tag/v2.4.0

…problem solved, thanks!

@helaili Thanks for reporting! As a workaround, specify the project name as argument: gh repo create my-project.

Hi,

I want to be able to create repo from template and also i want to give direct access to a team with this single line command at the below.

gh repo create organization/repo-001 --template "organization/test-template-repo" --private --team "teamname"

However, I am getting this warning message.

The '--template' option is not supported with '--homepage, --team, --enable-issues or --enable-wiki'

I would like learn why I can not do this and Why I have to give direct access to team from web browser? Can we count this as feature request?

I can’t seem to get this to work in an empty directory, not only in a directory with a repo inside already:

ls -l /Users/andrewjanian/projects/ajtest
ls: cannot access '/Users/andrewjanian/projects/ajtest': No such file or directory
mkdir -p /Users/andrewjanian/projects/ajtest && cd /Users/andrewjanian/projects/ajtest && gh repo create --private -y ajanian/ajtest
✓ Created repository ajanian/ajtest on GitHub
fatal: remote origin already exists.
git: exit status 128

From reading the rest of this issue that should only be happening when the repo already exists, right?