Git update commit author on push event

46 Views Asked by At

We have a dev pc, multiple people uses it, but the problem is everybody is using it with the root account. We would like to automatically fill the commit author data by the push event, because on remote git there are separate accounts.

Is there a way to update the commit author on push event? Or is there any way to come over this problem without separate users on the dev pc?

Solution would be to change .gitconfig user.name and user.email or use --author everytime on a commit, but this solution is not reliable. On the server side we are using GitLab, and on the Activity tab is clear who pushed the commits, but on the commit list the author is always root.

I know if i update the author the history changes, so everything is changes

1

There are 1 best solutions below

0
Mr.Gitster On

It sounds from the 'root' mention that you are asking about a linux system.

That being the case, you could run a command each time the (root) user logs out that resets the git config to force the user to fill it in with their author information, something like

https://unix.stackexchange.com/questions/398890/forcing-command-to-run-on-logout

Which mentions script-running for both logging out of the Gnome GUI and logging out of a bash terminal.

If your dev team is not logging out root after completing a commit work, that is unusual and my suggestion would not really help.

Even simpler and better would be to set up new root-empowered users for each individual user. It is an extra responsibility for someone to step up as the PC admin, but if you must have the differentiated history that is really the way to go as updating the git author information is slightly more work than logging into a system.