1

I try to create a local branch and push it to remote. When I use the following code local branch created and when the execution comes to pushCommand.call() in pushHotfixBranchToRemote() method, it is throwing an exception

org.eclipse.jgit.api.errors.TransportException: ssh://approot@192.168.57.65:22/u01/gitroot/apdt_v16_test/dev/appbi.git: Auth fail

the above scenario happened while running the class on a Linux machine where the cloned source is present in same machine and the bare is present in another one.

But when i tried the same in my local machine(windows) where the clone and bare in same machine but different drive , it is working fine.

Some answer for these kinda questions says , that we hav to check .ssh folder. But i dont knw anything about it. kindly help me to solv

private void createLocalHotFixBranch() {
    CreateBranchCommand createBranchCommand = null;
    try {
        portalLogger.debug("Inside createLocalHotFixBranch()");
        createBranchCommand = gitObject.branchCreate();
        createBranchCommand.setName(GitBranchConstants.hotFixBranchName + "_" + releaseVersion)
            .setStartPoint("origin/" + GitBranchConstants.releaseBranchName).call();
    } catch (GitAPIException e) {
        portalLogger.error("Error occured in createLocalHotFixBranch  --> " + e.getMessage());
        e.printStackTrace();
    }
}

private void pushHotfixBranchToRemote() {
    PushCommand pushCommand = null;
    try {
        portalLogger.debug("Inside pushHotfixBranchToRemote()");
        pushCommand = gitObject.push();
        pushCommand.setRemote("origin");
        pushCommand.setRefSpecs(new RefSpec(GitBranchConstants.hotFixBranchName + "_" + releaseVersion + ":"
            + GitBranchConstants.hotFixBranchName + "_" + releaseVersion));
        pushCommand.call();
    } catch (GitAPIException e) {
        portalLogger.error("Error occured in pushHotfixBranchToRemote  --> " + e.getMessage());
        e.printStackTrace();
    }
}

exception is

org.eclipse.jgit.api.errors.TransportException: ssh://approot@192.168.57.65:22/u01/gitroot/apdt_v16_HotfixTest/dev/core.git: Auth fail
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:160)
at com.echain.project.HotFixBranchCreationTest.pushHotfixBranchToRemote(HotFixBranchCreationTest.java:121)
at com.echain.project.HotFixBranchCreationTest.initiateHotfixCreationProcess(HotFixBranchCreationTest.java:65)
at com.echain.project.HotFixBranchCreationTest.main(HotFixBranchCreationTest.java:169)
Caused by: org.eclipse.jgit.errors.TransportException: ssh://approot@192.168.57.65:22/u01/gitroot/apdt_v16_HotfixTest/dev/core.git: Auth fail
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:159)
    at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:136)
    at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:320)
    at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:166)
    at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
    at org.eclipse.jgit.transport.Transport.push(Transport.java:1200)
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:156)
    ... 3 more
Caused by: com.jcraft.jsch.JSchException: Auth fail
    at com.jcraft.jsch.Session.connect(Session.java:512)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
    ... 9 more
centic
  • 15,565
  • 9
  • 68
  • 125
Jothivignesh
  • 45
  • 1
  • 6
  • Possible duplicate of [Git SSH authentication](https://stackoverflow.com/questions/13425811/git-ssh-authentication) – phd Jul 27 '17 at 16:26
  • There are thousnad answers about [git ssh authentication](https://stackoverflow.com/search?q=%5Bgit%5D+ssh+authentication). – phd Jul 27 '17 at 16:27
  • Please provide the complete stacktrace. It would also be nice if you remove some cruft from the snippet. – Rüdiger Herrmann Jul 27 '17 at 16:55
  • @RüdigerHerrmann added the full stack in the question – Jothivignesh Jul 28 '17 at 07:29
  • On your local machine, it works because there is no authentication necessary.Most likely JGit can't find the ssh key that is needed to authenticate with the remote host. Can you clone the remote repository with CLI Git? – Rüdiger Herrmann Jul 29 '17 at 07:53
  • I cloned using normal git command lik git clone ssh://192..... .git. that works fine... Even i comitted and added tag wit egit api.. tat also works.. but when creating local branch and pushing it to client is not working... While pushing local branch to remote only i am facing – Jothivignesh Jul 29 '17 at 08:02
  • @RüdigerHerrmann i created git object lik this gitObject = new JGitUtils().getGIT("local url"), "bare.url"), "bare.password")); – Jothivignesh Aug 01 '17 at 04:09
  • Most likely you will need to tell JGit/JSch where to find the ssh key. It seems not to be in the default location. Maybe this article will help http://www.codeaffine.com/2014/12/09/jgit-authentication/ – Rüdiger Herrmann Aug 01 '17 at 07:17

0 Answers0