how to block root from using git

We have many small repos on a particular dev machine. This is a machine used by sysadmins.
People are suposed to always check in code as themselves. But some people get sloppy and commit as root.
I would like to know the most efficient way to block root from using git.

I’m thinking the best way would be something in /root/.gitconfig but I havent found the magic yet.

You need to use pre commit hook to check user.

Try this:

https://gist.github.com/raido/afdef127f0396438093976a99491b0a5

As I mentioned, we have many modules. 
Adding a special precommit hook to all the modules for this, isnt practical. We need a once-and-for-all fix.

You can set commit.template in root’s .gitconfig and point it to a file full of “DON’T COMMIT AS ROOT” :smiley:

1 Like