cli: "fatal:remote origin already exists" when creating repo

Describe the bug

Version

gh version 1.1.0 (2020-10-06)
https://github.com/cli/cli/releases/latest

Problem

When I want to create a GitHub repo via gh repo create Username/RepoName, I got some error.

Steps to reproduce the behavior

  1. Type the command gh repo create Username/new_repo_name
  2. View the output
  3. You will see error “fatal: remote origin already exists”

Expected vs actual behavior

  • Expected: I can create then clone the repo with gh repo create
  • actual behavior: I can create the repo, but can’t clone it. I need to run gh repo clone to clone it.

Logs

$ gh repo create Emojigit/example
? Visibility Public
? This will create 'Emojigit/example' in your current directory. Continue?  Yes
✓ Created repository Emojigit/example on GitHub
fatal: 遠端 origin 已經存在。
git: exit status 128

Translate:

  1. 遠端: remote
  2. 已經存在: already exists

About this issue

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

Most upvoted comments

@Emojigit Did you expect a sub-directory to be a created for the new repo instead of it being added as origin remote to the existing git repo?

FWIW, what I’m looking to do is create the remote repo from a template and then clone it locally. Should this just be two steps?

@Emojigit Sorry for the bad experience! Right now, gh users get this error when they try to run gh repo create in an existing local git repository that already has an origin remote. This is known and we will try to make this a better experience.

gh repo create was meant to either be run outside of a local repository, or inside of a local repository that has no existing git remotes.

For the record: when you ran gh repo create Username/new_repo_name, was your intention to create a new GitHub repo and clone it in a new directory called new_repo_name?

Another strange bug! Strange Bug!

@mislav When there is already an origin remote, should we skip this step or ask to change the current remote URL? 🤔

@Emojigit Sorry for the bad experience! Right now, gh users get this error when they try to run gh repo create in an existing local git repository that already has an origin remote. This is known and we will try to make this a better experience.

gh repo create was meant to either be run outside of a local repository or inside of a local repository that has no existing git remotes.

For the record: when you ran gh repo create Username/new_repo_name, was your intention to create a new GitHub repo and clone it in a new directory called new_repo_name?

I am writing some plugins of software that use git, so I need to run the gh repo create in another repo.

It looks like your repo was created: https://github.com/Emojigit/example Am I missing something?

@mislav - I would like to be able to specify the name of the remote when creating a repo.

For example, something like this: gh repo create --remote-name upstream

The scenario is that it is a git init’d directory and I want to create a repo and add it as a remote, but I already have origin specified.