title: JGit - Push a specific file to RemoteRepo
body: <p>What I have done till now is -</p>
  
  <ol>
  <li>Cloned from Remote Repo.</li>
  <li>Added a file to specific directory in my project and made some changes in that file</li>
  <li>Committed the file</li>
  <li><p>Trying to push the changes to Remote Repo
   // it's showing me message a null and status as OK but <strong>the file isn't getting pushed to the Remote Repo</strong>.</p>
  
  <p>Another Problem is when I am trying to print push message it's infinitely printing - <strong>Msg- null - Status - OK - refs/heads/master</strong></p></li>
  </ol>
  
  <hr>
  
  <pre class="lang-java prettyprint-override"><code>private static final String REMOTE_URL = "http://abc.def.net/git/scm/nt/myprojectname.git"
  
  String srcPath = "D://MyFiles//fol//ErrorFile.txt";
  
  // prepare a new folder for the cloned repository
  File localPath = File.createTempFile("TestGitRepository", "");
  localPath.delete();
  
  // then clone
  System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
  CredentialsProvider cp = new UsernamePasswordCredentialsProvider("myUserName","mypassword");
  
  Git git = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).setCredentialsProvider(cp).call();
  
  String head = git.getRepository().getFullBranch();
  if (head.startsWith("refs/heads/")) {
          // Print branch name with "refs/heads/" stripped.
          System.out.println("Current branch is " + git.getRepository().getBranch());
  }
  
  String destPath = localPath+"\\myprojectName\\" ;
  File srcFile = new File(srcPath);
  File destFile = new File(destPath);
  FileUtils.copyFileToDirectory(srcFile, destFile, true) ;
  
  git.checkout(); // MISSED THIS LINE EARLIER
  
  // run the add-call
  git.add().setUpdate(true).addFilepattern(destFile.getAbsolutePath()).call();
  
  RevCommit revCommit = git.commit().setMessage("My First Commit").call();
  System.out.println(revCommit.getShortMessage() );
  Iterable&lt;PushResult&gt; resultIterable = git.push().setCredentialsProvider(cp).call();
  
  while(resultIterable.iterator().hasNext()){               // LEADING TO INFINITE LOOP
  PushResult result = resultIterable.iterator().next();
  Collection&lt;RemoteRefUpdate&gt; rs = result.getRemoteUpdates();
    for(RemoteRefUpdate rf : rs){
      System.out.println("Msg- "+rf.getMessage() + " - Status - "+rf.getStatus() + " - "+rf.getSrcRef());
    }
  }
  
  try {
    System.out.println("Having repository: " + git.getRepository().getDirectory());
  } finally {
    git.getRepository().close();
  }
  </code></pre>