Skip to content

Gh cli reports “not a git repository” when creating a pr using --repo param #5075

@gilzow

Description

@gilzow

Describe the bug

When attempting to create a PR targeting a repository with --repo, the PR creation fails and the gh cli reports:
fatal: not a git repository (or any of the parent directories): .git

❯ gh --version
gh version 2.4.0 (2021-12-21)
https://github.com/cli/cli/releases/tag/v2.4.0
❯ gh auth status
github.com
  ✓ Logged in to github.com as gilzow (/Users/gilzow/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use ssh protocol.
  ✓ Token: *******************

I also did gh auth refresh just to make sure there wasn't something wrong with my token.

Steps to reproduce the behavior

  1. cd into a directory that does not contain a repository
  2. issue the create pr command targeting a specific repository with the --repo parameter:
gh pr create --head "update" --base "master" --title "title" --body "body" --repo gilzow/wordpress-composer

The repository gilzow/wordpress-composer exists
Its default branch is master
It has a branch update that is ahead of master and is eligible to be merged

  1. See error:
fatal: not a git repository (or any of the parent directories): .git
/usr/bin/git: exit status 128

Expected vs actual behavior

A PR should be created and a URL to the PR should be reported back.
I've tried this with several of my repositories and all exhibit the same behavior. If however, I cd into a local clone of the repository locally and issue the same command, it creates the PR as expected. However, this is being used as part of a larger automation where a local clone of the repository will not be present.

Logs

Is there a verbose or debug parameter to output additional information? If so, please let me know and I'll update this issue with the additional logs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2Affects more than a few users but doesn't prevent core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions