I have used below code to do push.
public static void main(String[] args) throws IOException,GitAPIException
{
Repository localRepo = new
FileRepository("C:\\Users\\Joshi\\Desktop\\demo");
Git git = new Git(localRepo);
// add remote repo:
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
try {
remoteAddCommand.setUri(new
URIish("https://bitbucket.org/nidhi011/bxc"));
System.out.println("file Added");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// you can add more settings here if needed
remoteAddCommand.call();
git.commit().setMessage( "commited" ).call();
// push to remote:
PushCommand pushCommand = git.push();
pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider("username", "password"));
// you can add more settings here if needed
pushCommand.call();
}
and my error is
file Added
Exception in thread "main"
org.eclipse.jgit.api.errors.WrongRepositoryStateException: Cannot commit on
a repo with state: BARE
at org.eclipse.jgit.api.CommitCommand.call(CommitCommand.java:171)
at maven_git.push.main(push.java:38)
After running the above code I got this exception error please help me to solve out the jgit push command. And yes One more thing when I exceutes this code it make config file in my local directory " demo" folder I can't understand that.