I am using the jgit . I am new to it i am able to clone the code from github but when i tried to push code in java it is giving me error.
Here's code : public class PullFromRemoteRepository {
private static final String REMOTE_URL = "https://github.com/raghav1/local.git";
public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
// prepare a new folder for the cloned repository
File localPath = File.createTempFile("raghav345", "");
localPath.delete();
// then clone
System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
Git.cloneRepository()
.setURI(REMOTE_URL)
.setDirectory(localPath)
.call();
// now open the created repository
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(localPath)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
Git git = new Git(repository);
git.pull()
.call();
System.out.println("Pulled from remote repository to local repository at " + repository.getDirectory());
repository.close();
}
}
Errors are coming like this:
Exception in thread "main" org.eclipse.jgit.api.errors.NoHeadException: Pull on repository without HEAD currently not supported at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:170) at org.dstadler.jgit.unfinished.PullFromRemoteRepository.main(PullFromRemoteRepository.java:61)
Can anybody help me where to set the path of head.
Thanks