Reputation: 113
I've configured ~/.gitconfig
correctly as below.
git config --global user.name "yuzhi"
git config --global user.email "[email protected]"
Here is the result.
saber@debian:~$ git config -l
user.name=yuzhi
[email protected]
core.editor=vim
color.ui=true
saber@debian:~$ git config --global -l
user.name=yuzhi
[email protected]
core.editor=vim
color.ui=true
What confuses me is that it does not work when i git commit
.
saber@debian:~/ics2020$ sudo git commit
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@debian.(none)')
But it works when i issue git commit
after the commands below.
git config --local user.name "yuzhi"
git config --local user.email "[email protected]"
BTW:
i'm running Debian-10.8
on the vmware.
and git==2.20.1
.
here is the similar question as mine, but i don't know how to solve in linux.
Upvotes: 2
Views: 5780
Reputation: 1323115
You can compare (assuming a recent enough Git, if not: update it) configuration with:
git config --show-origin --show-scope -l
sudo git config --show-origin --show-scope -l
You will clearly see the difference in paths (/home/saber/
vs. /root
), explaining why you don't see the same configuration.
That being said, as commented, don't use sudo
for regular commands like git
.
As noted in the comments, if the repository was initially created with sudo
(generating files owned by root
), the first commit (done with the regular user) will trigger:
saber@debian:~/ics2020$ git commit
fatal: Unable to create '/home/saber/ics2020/.git/index.lock': Permission denied.
That means you need to restore the proper ownership:
cd ~/ics2020
sudo chown -R $(id -u saber):$(id -g saber)
Then a simple commit (without sudo
) will work.
Upvotes: 3