diff --git a/hggit/__init__.py b/hggit/__init__.py
index 06a29fdd52a7f26c276b5ba16e3c445b402d565c_aGdnaXQvX19pbml0X18ucHk=..affd119533ae6de2aadf58227bcfe039996f9863_aGdnaXQvX19pbml0X18ucHk= 100644
--- a/hggit/__init__.py
+++ b/hggit/__init__.py
@@ -184,6 +184,14 @@
     # 1.7+
     pass
 
+def peer(orig, uiorrepo, *args, **opts):
+    newpeer = orig(uiorrepo, *args, **opts)
+    if isinstance(newpeer, gitrepo.gitrepo):
+        if isinstance(uiorrepo, localrepo.localrepository):
+            newpeer.localrepo = uiorrepo
+    return newpeer
+extensions.wrapfunction(hg, 'peer', peer)
+
 def revset_fromgit(repo, subset, x):
     '''``fromgit()``
     Select changesets that originate from Git.
diff --git a/hggit/gitrepo.py b/hggit/gitrepo.py
index 06a29fdd52a7f26c276b5ba16e3c445b402d565c_aGdnaXQvZ2l0cmVwby5weQ==..affd119533ae6de2aadf58227bcfe039996f9863_aGdnaXQvZ2l0cmVwby5weQ== 100644
--- a/hggit/gitrepo.py
+++ b/hggit/gitrepo.py
@@ -22,6 +22,7 @@
             raise util.Abort('Cannot create a git repository.')
         self.ui = ui
         self.path = path
+        self.localrepo = None
 
     def url(self):
         return self.path