My company uses GitHub for our organization repos and also validates authors by enforcing signed commits.
The problem is that it is possible to clone a repo, create a branch, submit several commits, and create a Pull Request without any signed commits. It isn't until there is an attempt to merge that PR into develop
or main
or whatever is the branch protected with signed commits where the PR merge fails. At that point, we have to clean it all up with a rebase
so that there are no commits without signatures.
Is there a way to enforce the signatures even on the local clone of the repo? Something like a pre-commit hook that ensures the commit fails if there is no signature? Something that, once set up, would look something like this:
> git clone <my-company's-git-repo-with-signatures-required-on-main-branch>
> cd <my-company's-git-repo-with-signatures-required-on-main-branch>
> git switch main # Just to make it clear that I am on the protected branch
> touch my-new-file
> git add my-new-file
> git commit -m "Testing" # And this is for a user that does not have signing set up yet.
Git Error: Cannot commit without signature # Or whatever the error message would be
This prevents any sort of "roll back" via rebase
or whatever other method may be possible.