1

I have an issue where i push my commits to remote repository. Basically remote repo gets my commits but the local repo still shows that im ahead of remote branch with x amount of commit.

Note: I checked the logs from git bash. Git fetch solves the problem from git bash but not from JGIT codes. My fetch works tested it many times Already checked similar issues like this

How to solve it?

Commit code:

git.add().addFilepattern(".").call();
git.commit().setMessage( "Commit for sideMerge branch").call();

Push Code:

tmpPush= git.push().setCredentialsProvider( new UsernamePasswordCredentialsProvider("ID","PW"));
tmpPush.setRemote("remote repolink");
tmpPush.call();
  • `PushCommand::call` returns a data structure that you can examine to find out if and what was pushed. – Rüdiger Herrmann Apr 24 '18 at 06:44
  • Basically this is what i get from pushresoult.getRemoteUpdates(); [RemoteRefUpdate[remoteName=refs/heads/master, UP_TO_DATE, (null)...3165adcd9f68af3a3bac8045e5de366dd2754895, srcRef=refs/heads/master, message=null]] – Szilágyi István Apr 24 '18 at 07:01
  • For me it seems its more like that the local HEAD pointer wont get updated. Local: commit HASHb9d (origin/master) Remote: commit HASH895 (HEAD -> master, sideMerge) – Szilágyi István Apr 24 '18 at 07:02
  • You didn't specified which remote branch to push. For example, push to `origin/master`, you should write `tmpPush.setRemote("origin").add("master")`. – Mincong Huang Apr 24 '18 at 07:10
  • Thanks this solved the problem. I don't understand why remote link stuff not working though. – Szilágyi István Apr 24 '18 at 07:15
  • Perhaps your local branch is not tracking the remote one, so you must add explicitly the target branch to push. If you want to track a remote branch in JGit, you can see @RüdigerHerrmann 's post [Make an existing Git branch track a remote branch with JGit?](https://stackoverflow.com/questions/33101533) – Mincong Huang Apr 24 '18 at 08:13

1 Answers1

2

As Mincong Huang said in the comments.

tmpPush.setRemote("origin").add("master")

code snippet solves the problem.

Code for Push:

tmpPush= git.push().setCredentialsProvider( new UsernamePasswordCredentialsProvider("ID","PW"));
tmpPush.setRemote("origin").add("master");
tmpPush.call();