public static void main(String[] args) throws IOException, GitAPIException { // prepare a new test-repository try (Repository repository = CookbookHelper.createNewRepository()) { try (Git git = new Git(repository)) { // create the file File myfile = new File(repository.getDirectory().getParent(), "testfile"); myfile.createNewFile(); // run the add git.add().addFilepattern("testfile").call(); // and then commit the changes git.commit().setMessage("Added testfile").call(); System.out.println( "Committed file " + myfile + " to repository at " + repository.getDirectory()); } } }