You can get Ref
that contains ObjectId
of HEAD
with 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, HEAD
you can also use things such as refs/heads/master
to get HEAD
branches master
, even if another branch is currently being checked.