Question

I've checked libgit2sharp v0.15.0 and it seems like there is no method for removing a remote.

Is there any way to do it?

Was it helpful?

Solution

I've checked libgit2sharp v0.15.0 and it seems like there is no method for removing a remote.

That's completely correct. Such a method doesn't exist yet as it's not supported by libgit2 yet.

There's a work in progress (see PR #1199) to implement this. Subscribing to this PR would let you know about it's future progress.

Is there any way to do it?

You can do it by hand this way:

  • Remove the whole config section that describes the remote to be deleted
  • Delete from the config every branch (remote, merge) tuple that depends on the remote to be deleted
  • Delete from .git/refs/remotes/ every remote tracking branch reference

For instance, if you're willing to drop the remote "useless"

Drop this whole section from the config

[remote "useless"]
    url = https://github.com/useless/project.git
    fetch = +refs/heads/*:refs/remotes/useless/*

Remove remote and merge entries from the two following branches

[branch "vNext"]
    remote = useless
    merge = refs/heads/vNext

[branch "topic/awesome_feature"]
    remote = useless
    merge = refs/heads/topic/awesome_feature

Delete the following references

 - .git/refs/remotes/useless/vNext
 - .git/refs/remotes/useless/topic/awesome_feature

Update

Pull Request #731 just made possible the removal of remotes through the API.

  • Syntax: repo.Network.Remotes.Remove(remoteName)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top