Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Unable to push file to a remote repository
Unable to push file to a remote repository [message #1779293] Fri, 05 January 2018 01:09 Go to next message
kelly wood is currently offline kelly woodFriend
Messages: 4
Registered: January 2018
Junior Member
I have been following the tutorial getting-started-with-jgit at codeaffine below to create a simple program to push a new file to a remote repository.

The code snippet looks like the ones below. It runs fine without any errors. I can see the file created locally after the file.createNewFile() line. However after the code finishes, the local file disappears, and the remote repo only has a commit message, but not the actual file. I am wondering what I am doing wrong?

String remoteURI = ....;
String localPath = ....;
String localFilePath = localPath + File.seperator + "testfile.txt";
Git git = Git.cloneRepository().setURI( remoteURI ).setDirectory( localPath ).call();
File file = new File(localFilePath);
file.createNewFile();
git.add().addFilePattern( localFilePath ).call();
git.commit().setMessage( "Create readme file" ).call();
git.push().call();
git.close();
Re: Unable to push file to a remote repository [message #1779397 is a reply to message #1779293] Sat, 06 January 2018 04:30 Go to previous messageGo to next message
kelly wood is currently offline kelly woodFriend
Messages: 4
Registered: January 2018
Junior Member
I did some more research and made the following changes to the code, but the file that I m trying to push to the remote repo is still not showing up. I m not sure why it doesn't help. Any tips on how to trouble shoot are appreciated.
...
git.commit().setAll(true).setMessage( "Create readme file" ).call();
git.remoteAdd().setName("origin").setUri(new URIish(remoteURI ).call();
git.push().call();
git.close();
Re: Unable to push file to a remote repository [message #1779415 is a reply to message #1779397] Sat, 06 January 2018 20:28 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Did you check if the commit you created looks ok in your local repository ?

try this:

git.push().setRemote("origin").setRefSpecs(new RefSpec("refs/heads/master:refs/heads/master")).call();
Re: Unable to push file to a remote repository [message #1779463 is a reply to message #1779415] Mon, 08 January 2018 10:24 Go to previous messageGo to next message
Aparna Argade is currently offline Aparna ArgadeFriend
Messages: 60
Registered: October 2010
Member
Today I tried multiple times, but I am also not able to push through egit. Is the same issue getting discussed here?
I'm using ssh. I was able to push my earlier patch set through this workspace, but today, I'm getting this error.
"Session.connect: java.net.SocketException: Connection reset".
'Configure Push->Dry-Run' also gives the same error after showing the progress dialog for 'Trying pushing to remote repositories'.
.log file of workspace reports exception as:
org.eclipse.jgit.errors.TransportException: ssh://user@git.eclipse.org:29418/swtbot/org.eclipse.swtbot: Session.connect: java.net.SocketException: Connection reset
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:172)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:137)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:336)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:174)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:160)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1310)
at org.eclipse.egit.core.op.PushOperation.run(PushOperation.java:189)
at org.eclipse.egit.ui.internal.push.PushOperationUI.execute(PushOperationUI.java:166)
at org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog.dryRun(SimpleConfigurePushDialog.java:320)
at org.eclipse.egit.ui.internal.dialogs.AbstractConfigureRemoteDialog.lambda$7(AbstractConfigureRemoteDialog.java:509)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.net.SocketException: Connection reset
at com.jcraft.jsch.Session.connect(Session.java:565)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:126)
... 10 more

I don't think that there is any connection problem from my side. Is something at backend changed?
Thanks,
Aparna
Re: Unable to push file to a remote repository [message #1779485 is a reply to message #1779415] Mon, 08 January 2018 14:53 Go to previous messageGo to next message
kelly wood is currently offline kelly woodFriend
Messages: 4
Registered: January 2018
Junior Member
Matthias Sohn wrote on Sat, 06 January 2018 20:28
Did you check if the commit you created looks ok in your local repository ?

try this:

git.push().setRemote("origin").setRefSpecs(new RefSpec("refs/heads/master:refs/heads/master")).call();


You are correct. It turns out the problem is that the new file was not added to the index, and thus not pushed to the remote repo. The problem was solved by changing the line to add a specific file to all files in the current directory:

git.add().addFilePattern( localFilePath ).call();

to:

git.add().addFilePattern( ".").call();

Re: Unable to push file to a remote repository [message #1806663 is a reply to message #1779485] Mon, 13 May 2019 12:34 Go to previous messageGo to next message
Avi NArisetty is currently offline Avi NArisettyFriend
Messages: 1
Registered: May 2019
Junior Member
i am creating maven project that is my project working directory i need to push that code to git repository how can i do that could you please help on this?
Re: Unable to push file to a remote repository [message #1806677 is a reply to message #1806663] Mon, 13 May 2019 18:00 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
I'm not sure why you're appending to this thread. Your question essentially boils down to "please help me understanding Git" and that is is completely unrelated. to this thread. In the end, this forum is for helping how best to use the Eclipse tools that support Git; it is not a "Git tutorial" forum.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Build and share EGit / JGit
Next Topic:Configuration of RGit from Centos
Goto Forum:
  


Current Time: Thu Apr 25 22:26:11 GMT 2024

Powered by FUDForum. Page generated in 0.04467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top