Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:25:45+00:00 2026-06-14T12:25:45+00:00

I’m trying to build a Java application that allows users to use Git based

  • 0

I’m trying to build a Java application that allows users to use Git based repositories. I was able to do this from the command-line, using the following commands:

git init
<create some files>
git add .
git commit
git remote add <remote repository name> <remote repository URI>
git push -u <remote repository name> master

This allowed me to create, add and commit content to my local repository and push contents to the remote repository.
I am now trying to do the same thing in my Java code, using JGit. I was able to easily do git init, add and commit using JGit API.

Repository localRepo = new FileRepository(localPath);
this.git = new Git(localRepo);        
localRepo.create();  
git.add().addFilePattern(".").call();
git.commit().setMessage("test message").call();

Again, all of this works fine. I couldn’t find any example or equivalent code for git remote add and git push. I did look at this SO question.

testPush() fails with the error message TransportException: origin not found. In the other examples I’ve seen https://gist.github.com/2487157 do git clone before git push and I don’t understand why that’s necessary.

Any pointers to how I can do this will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:25:46+00:00Added an answer on June 14, 2026 at 12:25 pm

    You will find in org.eclipse.jgit.test all the example you need:

    • RemoteconfigTest.java uses Config:

      config.setString("remote", "origin", "pushurl", "short:project.git");
      config.setString("url", "https://server/repos/", "name", "short:");
      RemoteConfig rc = new RemoteConfig(config, "origin");
      assertFalse(rc.getPushURIs().isEmpty());
      assertEquals("short:project.git", rc.getPushURIs().get(0).toASCIIString());
      
    • PushCommandTest.java illustrates various push scenario, using RemoteConfig.
      See testTrackingUpdate() for a complete example pushing an tracking a remote branch.
      Extracts:

      String trackingBranch = "refs/remotes/" + remote + "/master";
      RefUpdate trackingBranchRefUpdate = db.updateRef(trackingBranch);
      trackingBranchRefUpdate.setNewObjectId(commit1.getId());
      trackingBranchRefUpdate.update();
      
      URIish uri = new URIish(db2.getDirectory().toURI().toURL());
      remoteConfig.addURI(uri);
      remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/"
          + remote + "/*"));
      remoteConfig.update(config);
      config.save();
      
      
      RevCommit commit2 = git.commit().setMessage("Commit to push").call();
      
      RefSpec spec = new RefSpec(branch + ":" + branch);
      Iterable<PushResult> resultIterable = git.push().setRemote(remote)
          .setRefSpecs(spec).call();
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.