4

I wrote git ls-remote c-negation to retrieve the branches in my repository, which results in:

110bf702ee2653430aea50948dfb26ef0d1785da HEAD 4bff9fa1736ae5a5dc1f3becd4fd941720f04f83 refs/heads/hfix 739851a9d23553a5af23079c2e792952a9a0d93f refs/heads/master 9e1c1b066db9ae97025e985eace17fa5adac1b7d refs/heads/paper 110bf702ee2653430aea50948dfb26ef0d1785da refs/heads/t21 9e39cb92d8e48ff8b2d8bcea7341d0fc01df96ed refs/heads/t21-techrpt 739851a9d23553a5af23079c2e792952a9a0d93f refs/remotes/origin/HEAD be6205b5e8329939027a09456fade70f11a834a5 refs/remotes/origin/hfix 739851a9d23553a5af23079c2e792952a9a0d93f refs/remotes/origin/master 9e1c1b066db9ae97025e985eace17fa5adac1b7d refs/remotes/origin/paper fc23cecde3706e4a4b539de57e31865ecf4fde3e refs/remotes/origin/t21 0c527bc69858161bbe98d94bbdb8cffe653cc796 refs/remotes/origin/weak-seq 3661bc75f3d312a2527f9ace87a31efcd80a2224 refs/stash

However, when I write git checkout t21-techrpt and check the file c-negation on my computer, it does not list all the files which are on the online repository. I have tried pulling and fetching and this doesn't make a difference: I still can't see the files on the online repository in the branch t21-techrpt.

What is going on?

user65526
  • 685
  • 6
  • 19

2 Answers2

2

You would be better off using the new git switch command:

git fetch
git switch t21-techrpt

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

git switch -c <branch> --track <remote>/<branch>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

The result of the command ls-remote depends on the argument. It works with directories - lists local git repository, and with remote aliases - lists "online" repositories.

  1. When c-negation is your project directory.

Branch t21-techrpt present as a local branch - refs/heads/t21-techrpt, but it's not present as a remote one. It should be listed as refs/remotes/origin/t21-techrpt.

If you want to update your local branch with remote changes. Just pull it:

git pull origin t21-techrpt
  1. When c-negation is listed in git remote -v as alias.

The command should be like that:

git pull c-negation t21-techrpt
  • ``git pull c-negation t21-techrpt`` produces ``fatal: Couldn't find remote ref t21-techrpt`` and ``fatal: the remote end hung up unexpectedly``. – user65526 Dec 16 '21 at 11:01
  • So if the branch `t21-teckrpt` exists in remote `c-nagation` there is the same issue solution https://stackoverflow.com/a/6930399/6640136 – Aleksei Momot Dec 16 '21 at 11:42
  • But that question is about branches which you have created. I didn't create the branch ``t21-techrpt``, someone else did. – user65526 Dec 17 '21 at 10:43
  • So you haven't answered my question at all – user65526 Dec 19 '21 at 16:05
  • Let's go the full path. Branch `t21-techrpt` isn't present in local ones: ``` git branch ``` The remote repository URL with alias `` is the same as you expect: ``` git remote -v ``` And the branch `t21-techrpt` is present in remote repository as ` /refs/heads/t21-techrpt`: ``` git ls-remote ``` – Aleksei Momot Dec 20 '21 at 14:39
  • So using commands listed below should switch your project to the latest remote version. ``` git fetch t21-techrpt git checkout t21-techrpt ``` But `git fetch t21-techrpt` failed with `fatal: Couldn't find remote ref t21-techrpt` and `fatal: the remote end hung up unexpectedly` usually tells about remote branch you are looking for doesn't exist. It can be just a misprint in branch name, remote alias or remote URL. – Aleksei Momot Dec 20 '21 at 14:40
  • If they are correct means only the remote branch doesn't exist. You can check it by cloning project to another directory: ``` git clone cd dirname git branch -r ``` – Aleksei Momot Dec 20 '21 at 14:40
  • It does exist. I have seen it by going on the gitlab website, and my colleagues can access it. – user65526 Dec 21 '21 at 10:51