0

For the same centralized git repository, I created 2 local repositories via git clone; after working for a while, I did git pull --all so by right the two local repositories are the same.

However, there's a discrepancy --

From working folder A, in git bash command prompt, I can see a remote branch 'athos/ticket-1234':

$git branch -r
...
origin/athos/ticket-1234
...

and can check it out:

$git checkout athos/ticket-1234
Switched to a new branch 'athos/ticket-1234'
branch 'athos/ticket-1234' set up to track 'origin/athos/ticket-1234'.

While from working folder B, in git bash command prompt, I can not see the remote branch 'athos/ticket-1234', also can not check it out:

$git checkout athos/ticket-1234
error: pathspec 'athos/ticket-1234' did not match any file(s) known to git

I'm curious, what could happened, how could I find the root cause, and solve the issue?

Note: we have a coding practice that after a feature branch is merged back into the master branch, the developer shall delete the branch. So athos/ticket-1234 could be deleted by me, but I'm not sure now, as it appears somewhere but disappeared somewhere else.

athos
  • 6,120
  • 5
  • 51
  • 95
  • That checkout you are trying, you have already fetched before running it, right? – eftshift0 Feb 15 '23 at 11:08
  • @eftshift0 i did `git pull --all` first, then `git remote -v` and `git checkout athos/ticket-1234`. do I need do `git fetch`? – athos Feb 15 '23 at 11:10
  • Is there a branch called `athos/ticket-1234` (in any remote) if you run `git branch -r`? – eftshift0 Feb 15 '23 at 11:25
  • @eftshift0 from my working folder `A`, i can see an `origin/athos/ticket-1234` branch in the remote, but in working folder `B` i can't see it. – athos Feb 15 '23 at 11:28
  • Well, if the remote branch is not present in `B`, that is why checkout fails. Then the question is _why_ a remote branch that is visible on repo A is not visible on repo B. Are they looking at the same remote repo? And if they are, are they in sync? – eftshift0 Feb 15 '23 at 11:38
  • @eftshift0 both `A` and `B` are looking at the same remote repo. what do you mean by `in sync` pls? -- i did `git pull --all` on both sides, anything else i could do to check/ensure they are in sync? – athos Feb 15 '23 at 12:24
  • Well.... you have one (remote) branch in one... but not on the other. You said you have pulled (which is like a fetch). Does the branch exist in the remote repo? If it does, why doesn't one of the repos get to see it? If it does't exist (cause it was deleted), then that would help explain. – eftshift0 Feb 15 '23 at 12:58
  • @eftshift0 that's where i'm confused.. from one work directory `A`, seems that branch is on the remote but from the other, it doesn't. – athos Feb 15 '23 at 16:02
  • 4
    Probably, it's deleted.... and the repo where you saw it, has not had a `git fetch --prune` so it is still visible there. – eftshift0 Feb 15 '23 at 16:03
  • @eftshift0 thank you Ghostbuster! mysterious behavior explained. – athos Feb 15 '23 at 16:10
  • 1
    Had been dotting the path to the answer for a while... was waiting for you to connect them. Glad you _saw the light_. – eftshift0 Feb 15 '23 at 16:27
  • 1
    @eftshift0 when I read the question my first thought was: clone1, then branch deleted, then clone2, and pruning is off by default. I see you nailed it in the comments already and you might as well write up that answer for future readers. – TTT Feb 15 '23 at 16:53
  • 1
    This is not even a duplicate but an n-duple.... I am ok with it not being marked as a duplicate but won't write an asnwer for it. Thanks for the suggestion. – eftshift0 Feb 15 '23 at 17:39
  • I think this is one of those questions where you might not realize it's a dup until you know the answer, but now that you do: Does this answer your question? [Cleaning up old remote git branches](https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches) – TTT Feb 15 '23 at 18:07
  • @eftshift0 good point. From OP's point of view it may have been hard to realize it was a dup of "how to prune remote branches", but now that the answer is known, it could be marked as a dup. I voted to close with one of the more common remote pruning questions. – TTT Feb 15 '23 at 18:09
  • yeah... it's something "i don't know that i don't know", but now as i'm informed, it's a dup. – athos Feb 16 '23 at 13:33

0 Answers0