[英]Add remote via JGit
我在玩 JGit,我可以成功地从某个存储库( git remote rm origin
)中删除一个遥控git remote rm origin
,我该如何做一个git remote add origin http://github.com/user/repo
?
要删除我执行以下操作:
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();
显然它像老板一样工作。
有一些类可以添加新的类:
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
remoteAddCommand.setUri(new URIish("http://github.com/user/repo"));
remoteAddCommand.call();
还有一个RemoteSetUrlCommand
。
您可以使用git24j直接操作远程对象
Repository repo = Repository.open("your-repository");
Remote upstream = Remote.create(repo, "upstream", URI.create("http://github.com/user/repo"));
当然,你也可以通过 git-config API 做同样的事情:
Config cfg = Config.openOndisk("my-git.config");
cfg.setString("remote.url", "http://github.com/user/repo");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.