JGit PushCommand does not offer this feature (yet), but you can change the repository configuration, for example --set-upstream .
If you pass the remote alias to setRemote() (as the fragment from the question shows), you need to set the upstream as follows:
StoredConfig config = git.getRepository().getConfig(); config.setString( CONFIG_BRANCH_SECTION, "local-branch", "remote", "remote-alias-name" ); config.setString( CONFIG_BRANCH_SECTION, "local-branch", "merge", "refs/heads/name-of-branch-on-remote" ); config.save();
As a result of this configuration section
[branch "local-branch"] remote = remote-alias-name merge = refs/heads/name-of-branch-on-remote
If the remote has not yet been configured (ie there is no [remote "remote-alias-name"] section, you also need to create such a section. For example, for example:
config.setString( CONFIG_REMOTE_SECTION, "remote-alias-name", "url", "url-of-remote" ); config.setString( CONFIG_REMOTE_SECTION, "remote-alias-name", "fetch", "ref-spec" );
Constants are defined in the ConfigConstants class.
Rudiger herrmann
source share