Add remote via JGit

There are classes to add new ones:

    RemoteAddCommand remoteAddCommand = git.remoteAdd();
    remoteAddCommand.setName("origin");
    remoteAddCommand.setUri(new URIish("http://github.com/user/repo"));
    remoteAddCommand.call();

There is a RemoteSetUrlCommand too.


Managed it to work that way:

Git git = new Git(localRepository);
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", "http://github.com/user/repo");
config.save();

And aparently it works like a boss.

Tags:

Java

Git

Jgit