diff --git a/pygit2.c b/pygit2.c
index 6d083a7..fdfa895 100644
--- a/pygit2.c
+++ b/pygit2.c
@@ -278,8 +278,14 @@ Object_get_type(Object *self, void *closure) {
 
 static PyObject *
 Object_get_sha(Object *self, void *closure) {
+    const git_oid *id;
     char hex[GIT_OID_HEXSZ];
-    git_oid_fmt(hex, git_object_id(self->obj));
+
+    id = git_object_id(self->obj);
+    if (!id)
+        return Py_None;
+
+    git_oid_fmt(hex, id);
     return PyString_FromStringAndSize(hex, GIT_OID_HEXSZ);
 }
 
diff --git a/test/test_commit.py b/test/test_commit.py
index 07e1fab..4160f92 100644
--- a/test/test_commit.py
+++ b/test/test_commit.py
@@ -62,6 +62,7 @@ class CommitTest(utils.TestRepoTestCase):
         commit.committer = committer
         commit.author = author
 
+        self.assertEqual(None, commit.sha)
         self.assertEqual(pygit2.GIT_OBJ_COMMIT, commit.type)
         self.assertEqual(message, commit.message)
         # TODO: Uncomment when git_commit_set_message updates message_short.