Changing the remote url of a repository in libgit2sharp

How can we change the remote url of a repository?

var newUrl = "https://github.com/owner/my_repository.git";";

Remote remote = repo.Network.Remotes[name];

// This will update the remote configuration, persist it
// and return a new instance of the updated remote

Remote updatedremote = repo.Network.Remotes.Update(remote, r => r.Url = newUrl);

For what it's worth, most of the remote properties can be updated by following the same pattern. Feel free to take a peek at the RemoteFixture.cs test suite for more detailed examples.

Tags:

Libgit2Sharp