I have the problem, that we login to the systems as our own users johndoe and then have to do a sudo su - root to be able to do administrative tasks. We have the system config files in a git repository (which makes everything better). But now I lose the settings in the user's (johndoe) /home/johndoe/.gitconfig file.
I tried to set the $GIT_CONFIGvariable which works, but this is only for setting the repo configuration, not the global one and therefore the for me important variables won't be set:
$ sudo su - root
Hello johndoe. Switching your .gitconfig to /home/johndoe/.gitconfig
# git config --get user.name
John Doe
# git config --get user.email
[email protected]
# git config --global --get user.name
# git config --global --get user.email
#
This is the trick I tried:
$ cat .bashrc
--- snip ---
# load git config of user
LOGINUSER=$(who am i|awk '{print $1}')
if [ "$LOGINUSER" != "root" ]; then
GITCFGFILE="/home/$LOGINUSER/.gitconfig"
if [ -f $GITCFGFILE ]; then
echo "Hello $LOGINUSER. Switching your .gitconfig to $GITCFGFILE"
export GIT_CONFIG=$GITCFGFILE
fi
fi
Is there a way to set the path for the global git configuration?