8

How can we change the remote url of a repository?

using (var repository = new Repository(repositoryPath))
{
    //Change the remote url first
    //Then checkout 
}
Levent Esen
  • 559
  • 7
  • 18

2 Answers2

10

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.

Paul Farry
  • 4,730
  • 2
  • 35
  • 61
nulltoken
  • 64,429
  • 20
  • 138
  • 130
2

They had made public virtual Remote Update(Remote remote, params Action[] actions) obsolete.

var newUrl = "https://github.com/owner/my_repository.git";
WorkingRepository.Network.Remotes.Update("origin", r => { r.Url = uri; });
theofilis
  • 411
  • 5
  • 10