Add remote via JGit

Issue

I playing around JGit, I could successfully remove a remote from some repository (git remote rm origin), how can I do a git remote add origin http://github.com/user/repo ?

To remove I do the following:

StoredConfig config = git.getRepository().getConfig();
config.unsetSection("remote", "origin");
config.save();

But there’s no a option like #setSection(String, String).

Thanks in advance.

Solution

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();

Answered By – caarlos0

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published