2012-10-09 24 views
17

JGitで遊んでいたところ、一部のリポジトリ(git remote rm origin)からリモートを正常に削除できました。どうすればgit remote add origin http://github.com/user/repoを行うことができますか?JGit経由でリモートを追加する

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

しかし#setSection(String, String)のようなオプションはありませんがあります:私は、次の手順を実行を削除するには

ありがとうございます。

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

をそしてaparentlyそれが上司のように動作します:

答えて

31

はそのように動作し、それを管理していました。

+0

ここにgitとは何ですか? –

+1

'Git'のインスタンスです。 – caarlos0

0

新しいものを追加するためのクラスがあります。

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

RemoteSetUrlCommandがあまりにもあります。

関連する問題