git-hash-object - Linux


git-hash-object computes the object ID and optionally creates a blob from a given path.


git hash-object [-w] [-t <type>] <file>


  • -w: Write the object into the database
  • -t : Specify object type; allowed values: blob, commit, tag, tree


Compute the SHA1 hash of a file without storing it:

git hash-object my-file

Create and store a blob object:

git hash-object -w my-file

Common Issues

Error: object already exists:

If you try to write an object that already exists in the database, you will get this error. To overwrite an existing object, use git update-ref instead.


  • Use git-hash-object to create custom objects for Git repositories.
  • Combine with git add to stage and commit custom objects.
  • Use in scripts to programmatically manage Git objects.

Related Commands

  • git cat-file: Display or extract contents of objects
  • git update-ref: Update the reference to an object
  • git verify-object: Verify the validity of an object