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_CONFIG
variable 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
johndoe@somefirm.somewhere
# 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?
.gitconfig
file (as suggested in different other posts) is not a good solution because the possibility exists, that more than one user is logged in concurrently. – oXiVanisher Sep 19 '14 at 06:46git
orsu
. You should probably write down a problem statement, i.e. what exactly are you trying to achieve at the beginning of your question. Btw,sudo su -
is just a more complicated way to dosudo -i
? Alsogit config --global
is actually local to the user,[sudo] git config --system
handles the system-wide config. – Pavel Šimerda Sep 19 '14 at 07:33