   (let ((str (git-call-process-env-string nil "symbolic-ref" ref)))
     (and str (car (split-string str "\n")))))
 
-(defun git-update-ref (ref val &optional oldval)
+(defun git-update-ref (ref newval &optional oldval reason)
   "Update a reference by calling git-update-ref."
-  (apply #'git-call-process-env nil nil "update-ref" ref val (if oldval (list oldval))))
+  (let ((args (and oldval (list oldval))))
+    (push newval args)
+    (push ref args)
+    (when reason
+     (push reason args)
+     (push "-m" args))
+    (eq 0 (apply #'git-call-process-env nil nil "update-ref" args))))
 
 (defun git-read-tree (tree &optional index-file)
   "Read a tree into the index file."

  "Call git-commit-tree with buffer as input and return the resulting commit SHA1."
  (let ((author-name (git-get-committer-name))
        (author-email (git-get-committer-email))
        author-date log-start log-end args coding-system-for-write)
    (when head
      (push "-p" args)
      (push head args))
    (with-current-buffer buffer

                      (if (or (not (string-equal tree head-tree))
                              (yes-or-no-p "The tree was not modified, do you really want to perform an empty commit? "))
                          (let ((commit (git-commit-tree buffer tree head)))
                            (condition-case nil (delete-file ".git/MERGE_HEAD") (error nil))
                            (condition-case nil (delete-file ".git/MERGE_MSG") (error nil))
                            (with-current-buffer buffer (erase-buffer))
