# branch{u} not working even though upstream configured

2 messages from 2024-07-03 to 2024-07-06. Participants: Stefan Haller, Jeff King.
Thread: https://gitlist.dev/t/61723

## Stefan Haller, 2024-07-03 11:52

Subject: branch{u} not working even though upstream configured
Message-ID: <a04b3417-4590-48d1-bc6a-88ca44edb36c@haller-berlin.de>
URL: https://gitlist.dev/e/a04b3417-4590-48d1-bc6a-88ca44edb36c%40haller-berlin.de

```
What could be a reason why branch@{u} doesn't work even though the
branch does have a remote tracking branch configured?

We have a user who reports the following:

$ git push --set-upstream origin test-456
branch 'test-456' set up to track 'origin/test-456'.
Everything up-to-date
$ git merge-base test-456 test-456@{u}
fatal: upstream branch 'refs/heads/test-456' not stored as a
       remote-tracking branch

Git remote shows that the remote tracking branch is configured as expected:

$ git remote -v show origin
* remote origin
  [...]
  Local branches configured for 'git pull':
    test-456          merges with remote test-456
  Local refs configured for 'git push':
    test-456          pushes to test-456           (up to date)

Any ideas?

```

## Jeff King, 2024-07-06 07:09

Subject: Re: branch{u} not working even though upstream configured
Message-ID: <20240706070957.GB702644@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20240706070957.GB702644%40coredump.intra.peff.net
In-Reply-To: <a04b3417-4590-48d1-bc6a-88ca44edb36c@haller-berlin.de>

```
On Wed, Jul 03, 2024 at 01:52:05PM +0200, Stefan Haller wrote:

> What could be a reason why branch@{u} doesn't work even though the
> branch does have a remote tracking branch configured?
> 
> We have a user who reports the following:
> 
> $ git push --set-upstream origin test-456
> branch 'test-456' set up to track 'origin/test-456'.
> Everything up-to-date
> $ git merge-base test-456 test-456@{u}
> fatal: upstream branch 'refs/heads/test-456' not stored as a
>        remote-tracking branch
> 
> Git remote shows that the remote tracking branch is configured as expected:
> 
> $ git remote -v show origin
> * remote origin
>   [...]
>   Local branches configured for 'git pull':
>     test-456          merges with remote test-456
>   Local refs configured for 'git push':
>     test-456          pushes to test-456           (up to date)
> 
> Any ideas?

Hmm, in a simple test this seems to work for me. Can you show us what's
in your local .git/config, especially the relevant remote and branch
sections?  Likewise, can you show us "git for-each-ref" output to see
what refs you have (though from the message I think we are not even
getting as far as looking at the remote tracking branch itself)?

I was able to produce a similar error if "refs/heads/test-456" is not
covered by the remote.origin.fetch refspec. That's usually:

  [remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*

but if I delete that second line, or replace it with something like:

  fetch = +refs/heads/some-specific-branch:refs/remotes/origin/some-specific-branch

then I see the same error you saw.

-Peff

```
