Make an existing Git branch track a remote branch using JGit?

I use JGit to create a new git repository and everything that is already in the folder I save as a new branch.

I use

Git.init().setDirectory(workingDir).call();

(by default, the main branch is created after the above statement, so I rename it to "backupBranch"). because I clone the master from the remote master later.

The problem is that I click backup, clicking it, but not the remote tracking that I can install.

from terminal: if I use git branch -vv, result

master       5f1994c [origin/master] commitmsg
backupbranch 7a4d671 taking backup of file already in MyTests Folder..

According to Make Existing git Tracking Branch Remote Branch? I can use    git branch -u upstream/foofrom the terminal to indicate any time after clicking on backupbranch.

JGit.

,

git.branchRename().setNewName(backUpName).call();
git.add().addFilepattern(".").call();
RevCommit commit = git.commit().setMessage("taking backup of file already in MyTests Folder..").call();

.

Iterable<PushResult> pushResult = git.push().call();

, , .

+4
1

CreateBranchCommand

CreateBranchCommand create = git.branchCreate();
create.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
create.setName("develop");
create.setStartPoint("origin/develop");
create.setForce(true)
create.call();

setForce(true). , . (origin/develop), .

. :

StoredConfig config = git.getRepository().getConfig();
String branchName = "develop"
String remoteName = "origin";
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,  ConfigConstants.CONFIG_KEY_REMOTE, remoteName);
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + branchName);
config.save();

, :

[branch "develop"]
remote = origin
merge = refs/heads/develop
+4

Source: https://habr.com/ru/post/1611409/


All Articles