Dubslow
Dubslow

Reputation: 714

Git refuses to track or otherwise recognize the remote branch

git fetch origin doesn't get the new branch, and thus --track always fails, no matter what I try.

https://gist.github.com/dubslow/dab61346cc06d6b9cf7b

That's ^ everything I've tried. You'll note that I tried all the commands in the related question "Cannot update paths and switch to branch at the same time", but still no success. I have no idea what is going on.

Edit: With this new local branch, I tried to push to my own remote, but got this confusing message:

bill@Gravemind⌚1643 ~/qtox/libs/libtoxcore-latest ∰∂ git remote add mine ssh://[email protected]/dubslow/toxcore.git
bill@Gravemind⌚1644 ~/qtox/libs/libtoxcore-latest ∰∂ git push mine new_api
Counting objects: 566, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (461/461), done.
Writing objects: 100% (566/566), 549.87 KiB | 0 bytes/s, done.
Total 566 (delta 302), reused 260 (delta 102)
To ssh://[email protected]/dubslow/toxcore.git
 ! [remote rejected] new_api -> new_api (shallow update not allowed)
error: failed to push some refs to 'ssh://[email protected]/dubslow/toxcore.git'
bill@Gravemind⌚1644 ~/qtox/libs/libtoxcore-latest ∰∂ git push mine +new_api
Counting objects: 566, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (461/461), done.
Writing objects: 100% (566/566), 549.87 KiB | 0 bytes/s, done.
Total 566 (delta 302), reused 260 (delta 102)
To ssh://[email protected]/dubslow/toxcore.git
 ! [remote rejected] new_api -> new_api (shallow update not allowed)
error: failed to push some refs to 'ssh://[email protected]/dubslow/toxcore.git'

Edit: As Andrew C points out, those error messages meant the repo was a shallow clone, and I had totally forgotten, and the error messages were rather useless (except for when I tried to push, and those were only sort of useful to someone more experienced with git).

Upvotes: 0

Views: 266

Answers (2)

Andrew C
Andrew C

Reputation: 14903

This syntax

git checkout <branch>

When <branch> does not already exist will only work if <branch> exists on a single remote. If you have multiple remotes you need explicitly say which remote to track from with

git checkout -b <branch> <remote>/<branch>

This part of your error message

(shallow update not allowed)

Suggests you have a shallow clone, which can cause all kinds of strange behavior.

Upvotes: 2

engineerC
engineerC

Reputation: 2878

A simple git checkout new_api should work, assuming you don't have a local branch already of that name. The local ref you (accidentally) created of the same name will conflict, so delete it first with git branch -d new_api.

git checkout <branch>
   To prepare for working on <branch>, switch to it by updating
   the index and the files in the working tree, and by pointing HEAD at
   the branch. Local modifications to the files in the working tree are
   kept, so that they can be committed to the <branch>.

   If <branch> is not found but there does exist a tracking branch in
   exactly one remote (call it <remote>) with a matching name,
   treat as equivalent to

       $ git checkout -b <branch> --track <remote>/<branch>

Upvotes: 0

Related Questions