I would like to keep my dotfiles and other configuration files (especially in the /etc directory) in the git repository. But in order to write inside the /etc directory git must be run as root. This has an unacceptable consequence - it changes the owner and the group of files that git touches to root:root. Git also changes the owner of some of the files in the repository (e.g.
index) which makes it impossible to run it next time as a normal user.
Is it possible to run a command with escalated privileges but keep the current user, not root, as the one executing this command?