Skip to content

gh create repo takes parent directory name if parent directory contains .git #2026

@tomekpryjma

Description

@tomekpryjma

Describe the bug

The gh repo create command does not take the current directory's name if a parent directory has a .git folder inside it.

For example

I am in /var/www/html/toplevel/wp-content/plugins/my_plugin.

The directory /var/www/html/toplevel has a .git folder inside it (which is pointing to a remote origin) as well as a .gitignore which, amongst others, ignores the wp-content/plugins directory.

I want to create a new repository for my_plugin inside the wp-content/plugins/my_plugin directory.
I run the gh repo create command inside wp-content/plugins/my_plugin and get the following:

? Repository name (toplevel)

I then fill out Repository name manually, so the entire command input and its output looked like this:

$ gh repo create
? Repository name my_plugin
? Repository description 
? Visibility Public
? This will create 'toplevel' in your current directory. Continue?  Yes
✓ Created repository tomekpryjma/toplevel on GitHub
fatal: remote origin already exists.
git: exit status 128

Version

$ gh --version
gh version 1.0.0 (2020-09-16)
https://github.com/cli/cli/releases/tag/v1.0.0

Steps to reproduce the behavior

  1. git clone git@github.com:youruser/repository.git toplevel_directory
  2. cd toplevel_directory && echo nested_directory > .gitignore
  3. mkdir nested_directory && cd nested_directory
  4. gh repo create

Expected vs actual behavior

Expected behaviour
The gh repo create command takes the nested directory's name as the repository name and creates it in Git.

Actual behaviour
The gh repo create command takes the name of the parent directory that has a .git already initialised and uses that parent directory's name as the repository name and creates it in Git.

Logs

$ gh repo create
? Repository name my_plugin
? Repository description 
? Visibility Public
? This will create 'toplevel' in your current directory. Continue?  Yes
✓ Created repository tomekpryjma/toplevel on GitHub
fatal: remote origin already exists.
git: exit status 128

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions