Add remote via JGit


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 ?

To remove I do the following:

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

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

Thanks in advance.


Managed it to work that way:

Git git = new Git(localRepository);
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", "");;

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