diff --git a/usd/GitRepository.py b/usd/GitRepository.py
index 391fccd..c69238c 100644
--- a/usd/GitRepository.py
+++ b/usd/GitRepository.py
@@ -448,15 +448,11 @@ class USDGitRepository:
commit_tree += ['-p', upload_parent_commit]
commit_env = copy.copy(self._env)
commit_env.update(self.get_commit_environment(tree_hash, spi, patch_overrides))
- try:
- _, commit_msg_file = tempfile.mkstemp()
- with open(commit_msg_file, "wb") as fp:
- fp.write(msg)
- commit_tree += ['-F', commit_msg_file]
+ with tempfile.NamedTemporaryFile() as fp:
+ fp.write(msg)
+ fp.flush()
+ commit_tree += ['-F', fp.name]
cp = run(commit_tree, env=commit_env)
- finally:
- if commit_msg_file:
- os.unlink(commit_msg_file)
commit_hash = decode_binary(cp.stdout).strip()
self.update_head_to_commit(spi.head_name, commit_hash)