question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Branch has TrackedBranch for non existent branch

See original GitHub issue

LibGit2Sharp is reporting a tracked branch for a non-existent remote.

Output of git branch -a

  branch-no-remote
  master
* some-branch
  remotes/origin/master
  remotes/origin/some-branch

Here’s what libgit2sharp reports if I iterate through every branch in this repository and print out some properties:

  ---------------------------------------
  CanonicalName: refs/heads/branch-no-remote
  Tracked Branch: refs/remotes/origin/branch-no-remote
  IsTracking: True
  IsRemote: False
  IsCurrentRepositoryHead: False
  ---------------------------------------
  CanonicalName: refs/heads/master
  Tracked Branch: refs/remotes/origin/master
  IsTracking: True
  IsRemote: False
  IsCurrentRepositoryHead: False
  ---------------------------------------
  CanonicalName: refs/heads/some-branch
  Tracked Branch: refs/remotes/origin/some-branch
  IsTracking: True
  IsRemote: False
  IsCurrentRepositoryHead: True
  ---------------------------------------
  CanonicalName: refs/remotes/origin/master
  Tracked Branch: (null)
  IsTracking: False
  IsRemote: True
  IsCurrentRepositoryHead: False
  ---------------------------------------
  CanonicalName: refs/remotes/origin/some-branch
  Tracked Branch: (null)
  IsTracking: False
  IsRemote: True
  IsCurrentRepositoryHead: False

Notice that refs/heads/branch-no-remote is reporting a tracked branch of refs/remotes/origin/branch-no-remote which does not exist in this repository.

Where’s it getting it? From the .git\config I suppose.

[core]
    bare = false
    repositoryformatversion = 0
    filemode = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "origin"]
    url = https://github.com/Haacked/publish-test.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "some-branch"]
    remote = origin
    merge = refs/heads/some-branch
[branch "branch-no-remote"]
    remote = origin
    merge = refs/heads/branch-no-remote

I suspect that libgit2sharp is using the branch remote info to populate the TrackedBranch property. But it probably shouldn’t, right?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
haackedcommented, Mar 29, 2013

@dahlbyk so what’s the cleanest way to determine if the TrackingBranch really is tracking something?

branches[branch.TrackingBranch.Name] != null

0reactions
felixfbeckercommented, May 9, 2019

I also got tripped up by this. What is the recommended way to check?

branch.TrackedBranch.Tip != null
// or maybe
branch.TrackedBranch.Reference is VoidReference

?

What do you think about adding an IsGone property to Branch? That would use the same wording that git branch -vv uses for gone branches:

  deduplicate                               9b9cb5ec42 [origin/deduplicate: gone] deduplicate

and devs would hopefully use that property before getting tripped up by TrackedBranch

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to create branch that is tracking non-existing ...
This is a bash function that sets up a new local branch such that git push from that branch pushes to a new...
Read more >
How can I tell a local branch to track a remote branch?
Let's talk about both the concept and the practice of "tracking" branches. ... Your local branch now has a "counterpart" on the remote...
Read more >
I need to remove a remotely tracked branch that doesn't ...
The git fetch / git remote operation fetches the full current state of the remote repository into the remote tracking branches in your...
Read more >
git pull from remote but no such ref was fetched?
It's possible that someone else on your team simply merged your branch and deleted it (commonly done after merging). You can make the...
Read more >
Easily Perform Git Checkout Remote Branch [Step-by-Step]
Learn how perform Git checkout remote branch, effectively track remotes, and best practices to manage remotes and branches.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found