How-Tos

How-To: Check Which Hash Your Git Repos Use, and Try a SHA-256 Repo Locally

Leave a comment

GitHub just put SHA-256 repositories into public preview. Before you create one there, it’s worth knowing what your existing repos use and kicking the tires locally. This works on Omarchy, any Linux box or a Mac.

1. Check your Git version

git --version

You need 2.30 or newer for SHA-256 repos.

2. See what a repo uses

cd your-repo
git rev-parse --show-object-format

It prints sha1 or sha256. To check every repo under a folder:

for d in ~/src/*/; do [ -d "$d/.git" ] && printf '%s %s\n' "$(git -C "$d" rev-parse --show-object-format)" "$d"; done

3. Make a throwaway SHA-256 repo

mkdir /tmp/sha256-test && cd /tmp/sha256-test
git init --object-format=sha256
echo hello > README.md
git add README.md && git commit -m "first"
git log --format=%H -1

That hash is 64 characters instead of 40.

4. Look for scripts that assume 40 characters

grep -rnE '\{40\}|\b40\b' --include='*.sh' --include='*.py' --include='*.yml' .

It’s a rough search, but it finds regexes and length checks that will break on 64-character IDs.

Tips

  • You can’t convert a repo’s hash later, so decide at creation time.
  • Don’t switch a production repo until your CI, hooks and any libgit2-based tools are tested against a SHA-256 test repo.

God Bless, and Happy hacking!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.