version control - Git can not checkout another orphan branch from an orphan branch -
on machine1 create orphan branch git checkout --orphan branch1
.
on machine2 cloned repository 1 branch git clone <url> --branch branch1 --single-branch
. worked expected.
back on machine1 created new second orphan branch git checkout --orphan branch2
.
on machine2 when git fetch origin -- branch2
responds with:
* branch branch2 -> fetch_head
but when try checkout branch git checkout branch2
see
error: pathspec 'branch2' did not match file(s) known git.
i can't figure out how fetch , checkout second orphan branch machine2. because started off single-branch
clone?
first, side note: orphan branch branch no parent and no commits. since has no commits, doesn't exist. once make commit on it, it's no longer orphan: has commit, can parent; stops being orphan branch @ all. ordinary branch, every other branch. unusual repository has 2 (or more) root commits: commits have no parent.
since able git fetch
these things, not orphan branches; branches. "orphanness" (or lack thereof) red herring.
what's going on
... when
git fetch origin -- branch2
as petseral noted in comment, refspec arguments git fetch
can, , should, contain both remote source part and destination part:
git fetch origin src:dst
the source part can abbreviated (as in branch2
) or spelled out (refs/heads/branch2
, quite getting branch , not tag or something). destination part remote-tracking branch name (which not branch!) in own repository, such refs/remotes/origin/branch2
.
the refspec can (and remote-tracking branches, should) start plus sign, telling git overwrite own reference regardless of means you. remote-tracking branch names, overwriting sensible. local branch names, it's more questionable.
normally don't have of this
if git version @ least 1.8.4, git fetch
figures out on own. single-branch clones different:
is because started off single-branch clone?
yes! single-branch clone, clone have default fetch
refspec set match single branch. is, git fetch
looks @ repository's configuration, , configuration says: don't keep track of upstream except 1 single branch.
you're trying fetch different branch, git fetch
assumes don't want keep track of it. dumps result temporary fetch_head
file every fetch dumps (for historical reasons among others) , forgets it.
if convert single-branch clone normal clone, editing fetch =
line read way does, now-normal clone behave, well, normally. see how "undo" --single-branch clone? details (the accepted answer there assumes 1 remote, named origin
).
Comments
Post a Comment