Skip to content

Checking out an upstream branch creates error: "fatal: '<remote>/<branch>' is not a commit and a branch '<branch>' cannot be created from it #5385

@rolfedh

Description

@rolfedh

Describe the bug

When I use gh repo clone to create a local copy of my fork, if I check out a branch from the upstream branches, I get the following error message. This only happens when I use gh repo clone, not when I use git clone to create the local copy of my fork:

$ git checkout -b enterprise-4.9 upstream/enterprise-4.9
fatal: 'upstream/enterprise-4.9' is not a commit and a branch 'enterprise-4.9' cannot be created from it

Steps to reproduce the behavior

$ mkdir trash
$ cd trash
$ gh repo clone rolfedh/openshift-docs
Cloning into 'openshift-docs'...
remote: Enumerating objects: 279356, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 279356 (delta 2), reused 0 (delta 0), pack-reused 279352
Receiving objects: 100% (279356/279356), 600.42 MiB | 10.84 MiB/s, done.
Resolving deltas: 100% (189494/189494), done.
Updating upstream
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (47/47), done.
remote: Total 64 (delta 47), reused 47 (delta 47), pack-reused 17
Unpacking objects: 100% (64/64), 288.94 KiB | 1.43 MiB/s, done.
From https://github.com/openshift/openshift-docs
 * [new branch]            main       -> upstream/main
$ cd openshift-docs/
(main=) $ git remote -v
origin	https://github.com/rolfedh/openshift-docs.git (fetch)
origin	https://github.com/rolfedh/openshift-docs.git (push)
upstream	https://github.com/openshift/openshift-docs.git (fetch)
upstream	https://github.com/openshift/openshift-docs.git (push)
(main=) $ git fetch --all
Fetching origin
Fetching upstream
(main=) $ git branch
* main
(main=) $ git checkout -b enterprise-4.9 upstream/enterprise-4.9
fatal: 'upstream/enterprise-4.9' is not a commit and a branch 'enterprise-4.9' cannot be created from it
 openshift-docs (main=) $ 

Expected vs actual behavior

What you expected to happen: I expect the following command to work like it does when I use git clone:

(main=) $ git checkout -b enterprise-4.9 upstream/enterprise-4.9
Branch 'enterprise-4.9' set up to track remote branch 'enterprise-4.9' from 'upstream'.
Switched to a new branch 'enterprise-4.9'

What actually happened: When I use gh clone repo, the following command doesn't work:

(main=) $ git checkout -b enterprise-4.9 upstream/enterprise-4.9
fatal: 'upstream/enterprise-4.9' is not a commit and a branch 'enterprise-4.9' cannot be created from it

Logs

NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions welcomepriority-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