You can get Refthat contains ObjectIdof HEADwith the following:
Ref head = repository.getRef("HEAD");
System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName());
It produces something like this
Ref of HEAD: SymbolicRef[HEAD -> refs/heads/master=f37549b02d33486714d81c753a0bf2142eddba16]: HEAD - f37549b02d33486714d81c753a0bf2142eddba16
See also related snippet in jgit-cookbook
Instead, HEADyou can also use things such as refs/heads/masterto get HEADbranches master, even if another branch is currently being checked.