Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent root from running git pull?

Have need to prevent root from updating a git (working) directory. Reasoning includes but not limited to: preventing undersired file-system ownership changes.

None of the git hooks seem to prevent a fetch/merge/pull before it happens, similar to pre-commit hook. Or at least, nothing I see here (or in man page): http://www.analysisandsolutions.com/code/git-hooks-summary-cheat-sheet.htm

Thoughts?

like image 496
Johnny Utahh Avatar asked Oct 20 '12 01:10

Johnny Utahh


People also ask

How do I prevent git from requiring Sudo on every git command?

Change the current working directory to your local project. List your existing remotes in order to get the name of the remote you want to change. Change your remote's URL from HTTPS to SSH with the git remote set-url command. Verify that the remote URL has changed.

Does GIT keep file permissions?

Git Tracks ONLY the Executable Bit of the Permissions for the User Who Owns the File.

How do I find my git hooks?

The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that's . git/hooks .


2 Answers

The only way I saw this not resolved but at least "mitigated" was through a wrapper for the git command:

All git commands go through this wrapper which proceeds if the user id is not root.

like image 103
VonC Avatar answered Oct 12 '22 23:10

VonC


Change /root/.bashrc to add a new directory to the beginning of the PATH. Add a shell script there called git that tests $1 to be one of a few read-only commands (show/status/log/rev-list etc) and calls /usr/bin/git "$@" if the command is acceptable. This will prevent anybody on your team from accidentally running git pull as root. If you are worried about them doing it deliberately, you have bigger problems...

like image 40
r3m0t Avatar answered Oct 12 '22 23:10

r3m0t