Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the remote url of a repository in libgit2sharp

Tags:

libgit2sharp

How can we change the remote url of a repository?

using (var repository = new Repository(repositoryPath))
{
    //Change the remote url first
    //Then checkout 
}
like image 935
Levent Esen Avatar asked May 15 '15 09:05

Levent Esen


1 Answers

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.

like image 122
nulltoken Avatar answered Sep 29 '22 15:09

nulltoken