I want to implement this commmand in Git,But I don't know what to do?
push origin HEAD:refs/for/master
I want to implement this commmand in Git,But I don't know what to do?
push origin HEAD:refs/for/master
Try something like the following example:
public static void push(String remoteUrl, Repository repo, StandardCredentials credential, String localBranchRef, String remoteBranchRef) {
try (org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repo)) {
String pushSpec = "+" + localBranchRef + ":" + remoteBranchRef;
PushCommand pushCommand = git.push();
addCredential(repo, pushCommand, credential);
Iterable<PushResult> resultIterable = pushCommand
.setRefSpecs(new RefSpec(pushSpec))
.setRemote(remoteUrl)
.call();
PushResult result = resultIterable.iterator().next();
if (result.getRemoteUpdates().isEmpty()) {
throw new RuntimeException("No remote updates occurred");
} else {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
if (!RemoteRefUpdate.Status.OK.equals(update.getStatus())) {
throw new ServiceException.UnexpectedErrorException("Remote update failed: " + update.getStatus().name() + ": " + update.getMessage());
}
}
}
} catch (GitAPIException e) {
if (e.getMessage().toLowerCase().contains("auth")) {
throw new ServiceException.UnauthorizedException(e.getMessage(), e);
}
throw new ServiceException.UnexpectedErrorException("Unable to save and push to: " + remoteUrl + " - " + e.getMessage(), e);
}
}
You can find more info and examples here.