git

All posts tagged git

In git, it is possible in the default configuration for anyone with commit permission to really mess things up. Someone can do a force push and wipe out everyone else’s commits.

Stop all force pushes

The bare authoritative repository can be configured to deny non-fast-forward commits such as this even when forced. An overview of this is in Git Configuration in the git book. The main settings are:

git config --system receive.denyNonFastForwards true

git config --system receive.denyDeletes true

Note that --system here will write to the /etc/gitconfig file.

Stop some force pushes

For individual branches, there is a pre-receive hook available here on Github.

I have also heard that it is possible to prevent specific users from force pushing using a pre-receive hook on the server.

Note that it is not possible to add the above on Github – the workaround is to let only a limited number of people commit, and have everyone else use pull requests.

Maybe stop some force pushes

Another option is to add a pre-push hook to run on the client, which can be used for projects on Github. This is not strictly enforceable, since a user could remove it and still do a forced push, but it can prevent accidental pushing to master, and would be a decent safety net for people new to git to make sure they can’t accidentally break something too much. Some good-looking instructions for setting it up are in the blog post Do not allow force push to master.

Fast-Forward Only Pull Requests on GitHub

Just email GitHub and ask for them, according to @domenic: