Search code examples
gitgit-branchgit-remotegit-checkoutgit-fetch

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://git@github.com/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://git@github.com/dubslow/toxcore.git
 ! [remote rejected] new_api -> new_api (shallow update not allowed)
error: failed to push some refs to 'ssh://git@github.com/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://git@github.com/dubslow/toxcore.git
 ! [remote rejected] new_api -> new_api (shallow update not allowed)
error: failed to push some refs to 'ssh://git@github.com/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).


Solution

  • 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.