4

I had seen other similar questions but not a functional code that fetchs or pulls using JGit. Could anyone help me with a small pulling example or explanation that doesn't throws a JGIT Pull NoHeadException.

Thanks in advance

1 Answers1

0

You can see examples in JGit Cookbooks:

That is:

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
        System.out.println("Starting fetch");
        try (Git git = new Git(repository)) {
            FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
            System.out.println("Messages: " + result.getMessages());
        }
    }
}

That is:

try (Git git = new Git(repository)) {
    PullResult call = git.pull().call();
    System.out.println("Pulled from the remote repository: " + call);
 }
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250