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.

Pushing new branches does not set up tracking branch completely

See original GitHub issue

When you push a local branch that does not exist on the remote (using the refspec overload), libgit2sharp automatically creates a tracking branch, but it does not set up the config for the local branch

i.e. the following config entries are missing:

branch.(branch_name).remote
branch.(branch_name).merge

Currently, I push a new branch like as follows:

string refspec = string.Format("{0}:{1}",
    currentBranch.CanonicalName, currentBranch.CanonicalName);
repo.Network.Push(remote, refspec, handler, credentials);
repo.Branches.Update(repo.Head, delegate(BranchUpdater updater)
{
    updater.Remote = remote.Name;
    updater.UpstreamBranch = repo.Head.CanonicalName;
});

I feel like this should be simplified. Either by doing the BranchUpdater stuff in Push(), or by extending the Push(Branch, ...) overload to let it accept non-tracking branches and do the whole process.

I also did not find a test fixture covering that feature, so the intended behaviour should at least be specified.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Lapeno94commented, Oct 15, 2022

Hey @wilkovanderveen,

There is a workaround how to solve this.

`

       var pushOptions = new PushOptions
        {
            CredentialsProvider = (_, _, _) =>
                new UsernamePasswordCredentials()
                {
                    Username = yourUsername,
                    Password =yourPassword
                }
        };
        
       // branch -> your local branch which are you working on name: feature/foo/bar
       // trackedBranchName -> refs/remotes/origin/feature/foo/bar
       
        repository.Network.Push(repository.Network.Remotes["origin"], branch.CanonicalName, trackedBranchName, 
            pushOptions);
            
       // update branch references
        repository.Branches.Update(repository.Head, updater =>
        {
            updater.Remote = repository.Network.Remotes["origin"].Name;
            updater.UpstreamBranch = repository.Head.CanonicalName;
        });
        // push to the server
        repository.Network.Push(repository.Branches[branchName], pushOptions);`
0reactions
wilkovanderveencommented, Aug 15, 2022

I know this topic is from 9 years ago. But is this fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

There is no tracking information for the current branch
This happens due to current branch has no tracking on the branch on the remote. so you can do it with 2 ways....
Read more >
Fix Git's "fatal: no upstream branch" error quickly example
The simple solution to the current problem is easily solved by issuing the following Git push upstream command:
Read more >
How To Set Upstream Branch on Git
Complete step-by-step tutorial on how to set upstream branches (remote tracking branches) on Git easily using branch commands.
Read more >
Git - Remote Branches
Remote-tracking branches are references to the state of remote branches. They're local references that you can't move; Git moves them for you whenever...
Read more >
Git Push to Remote Branch – How to Push a Local ...
The basic command for pushing a local branch to a remote repository is git push. This command has a variety of options and...
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