diff --git a/hggit/git_handler.py b/hggit/git_handler.py
index e7316a108780dfc2cb469ac03b96bae38d537e5e_aGdnaXQvZ2l0X2hhbmRsZXIucHk=..8140bbc2fdc2062c6d957b0e288a3ab45030a95e_aGdnaXQvZ2l0X2hhbmRsZXIucHk= 100644
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -21,6 +21,7 @@
 from mercurial import commands
 from mercurial import context, util as hgutil
 from mercurial import url
+from mercurial import lock as lockmod
 
 import _ssh
 import git2hg
@@ -1308,5 +1309,5 @@
                         bms[head + suffix] = hgsha
 
             if heads:
-                wlock = self.repo.wlock()
+                tr = lock = wlock = None
                 try:
@@ -1312,3 +1313,11 @@
                 try:
-                    bms.write()
+                    wlock = self.repo.wlock()
+                    lock = self.repo.lock()
+                    tr = self.repo.transaction('git_handler')
+                    if hgutil.safehasattr(bms, 'recordchange'):
+                        # recordchange was added in mercurial 3.2
+                        bms.recordchange(tr)
+                    else:
+                        bms.write()
+                    tr.close()
                 finally:
@@ -1314,5 +1323,5 @@
                 finally:
-                    wlock.release()
+                    lockmod.release(tr, lock, wlock)
 
         except AttributeError:
             self.ui.warn(_('creating bookmarks failed, do you have'