diff --git a/hggit/git_handler.py b/hggit/git_handler.py
index 3ca3ee14a659a96c3f593567fc0dc3d735e06c28_aGdnaXQvZ2l0X2hhbmRsZXIucHk=..7486e8dd63aab07c8be217961fd4a835c599dadd_aGdnaXQvZ2l0X2hhbmRsZXIucHk= 100644
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -1707,6 +1707,22 @@
 
             return [(_filter_bm(bm), bm, n) for bm, n in bms.items()]
 
+    def _ensure_unique_refs(self, exportable):
+        """Ensure that each ref is used for only one changeset."""
+        ref2nodes = {}
+        for node, refs in exportable.items():
+            for ref in refs:
+                ref2nodes.setdefault(ref, set()).add(node)
+        non_unique = [
+            (ref, nodes) for ref, nodes in ref2nodes.items() if len(nodes) > 1
+        ]
+        if non_unique:
+            lines = [_(b"ref(s) used for multiple changesets:")] + [
+                b"  %s -> %s" % (ref, b", ".join(sorted(nodes)))
+                for ref, nodes in non_unique
+            ]
+            raise error.Abort(b"\n".join(lines))
+
     def get_exportable(self):
         class heads_tags(object):
             def __init__(self):
@@ -1739,6 +1755,7 @@
 
         for tag, sha in self.tags.items():
             res[sha].tags.add(LOCAL_TAG_PREFIX + tag)
+        self._ensure_unique_refs(res)
         return res
 
     def import_tags(self, refs):
diff --git a/tests/test-same-ref-for-multiple-changesets.t b/tests/test-same-ref-for-multiple-changesets.t
new file mode 100644
index 0000000000000000000000000000000000000000..7486e8dd63aab07c8be217961fd4a835c599dadd_dGVzdHMvdGVzdC1zYW1lLXJlZi1mb3ItbXVsdGlwbGUtY2hhbmdlc2V0cy50
--- /dev/null
+++ b/tests/test-same-ref-for-multiple-changesets.t
@@ -0,0 +1,28 @@
+Test that there is an error if the same ref is used for multiple changesets.
+
+  $ . "$TESTDIR/testutil"
+  $ create_commit() {
+  >   echo $1 > $1
+  >   hg add $1
+  >   fn_hg_commit -m "add $1"
+  > }
+
+  $ hg init
+  $ cat << EOF >> .hg/hgrc
+  > [git]
+  > intree = yes
+  > branch_bookmark_suffix = _bookmark
+  > EOF
+
+  $ create_commit alpha
+  $ hg bookmark foo --inactive
+  $ create_commit beta
+  $ hg bookmark foo_bookmark --inactive
+
+  $ hg log --template "{node|short} {bookmarks}\n" $@
+  a7b2ac5cbfff foo_bookmark
+  0221c246a567 foo
+  $ hg gexport
+  abort: ref(s) used for multiple changesets:
+    refs/heads/foo -> 0221c246a56712c6aa64e5ee382244d8a471b1e2, a7b2ac5cbfff7c3ce3beda1a2db4ffeb047581d2
+  [255]