簡體   English   中英

通過 JGit 添加遠程

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM