0

After some trial and error I was able to change the permissions of the .gitconfig file in my local users /home/ directory. This permission change allowed me to add both user.name and user.email. I apologize if this wasted anyone's time and I do appreciate all of the help. Specifically @phd, @jD3V and @VonC

I am really banging my head against my desk with this one.

I have a remote GitHub repo that I have cloned locally to my machine and I am making edits to the playbook. When I go to commit the changes to GitHub VSCode throws an error:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  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: no email was given and auto-detection is disabled
[2022-04-23T18:08:35.512Z] > git config --get-all user.name [1ms]

I have run into this issue before, no big deal. This is a fresh install of Pop!_OS so I had not yet edited my git config. I enter the following -

git config --global user.name My_GitHub_Username

Followed by -

git config --global user.email My_email_name@gmail.com

When entered they both seem to run correctly as I do not get any errors thrown when entered. However when I check the git config with git config --list nothing returns in the terminal. When I run it again running as root, I see my username -

username@pop-os:~$ sudo git config --list
user.name=My_GitHub_username
user.email=My_email_name@gmail.com

Trying to commit the code again throws the same error. I have checked similar threads/solutions here, here and here, all of which have not solved my issue.

I forgot to include initially that I have tried running both as sudo and have the same results. Here is the output of `sudo nano ~/.gitconfig -

[alias]
    lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
    lg = !"git lg1"
[color]
    ui = true
[help]
    autocorrect = 3

Would I just go ahead and add the [user] alias with the user.name and user.email options filled in?

Any ideas what I might be doing incorrectly? I am not super familiar with git but would love any and all advice.

FRALEWHALE
  • 65
  • 2
  • 2
  • 13
  • 2
    `sudo` damn it! – phd Apr 23 '22 at 18:47
  • 1
    Well first of all, you tagged the question wrong. Secondly, you have different layers of git configurations, which is why, when you use the `--list` flag as the `ROOT` user, your getting a different result, but the result your getting as `ROOT` user is irrelivent, you need to edit your `.gitconfig` configuration files directly using `nano ~/.gitconfig` (or if your using vscode, you can use `code ~/.gitconfig`. – JΛYDΞV Apr 24 '22 at 01:19
  • As @VonC and phd have already suggested. – JΛYDΞV Apr 24 '22 at 01:22
  • I forgot to include that I did infact also try running the commands as sudo with the same result @Phd – FRALEWHALE Apr 24 '22 at 11:59
  • @FRALEWHALE Yes, that exactly the problem. Do not use `sudo` when you do not need it (and you almost never need it) and especially when you do not understand it. – phd Apr 24 '22 at 12:03
  • @phd I have also tried it without `sudo` and that did not work either, so then what would my solution be? When I run it I get without `sudo` I get an error - `warning: unable to access '/home/USERNAME/.gitconfig': Permission denied` Which is obviously a permissions issues but I am not sure how my local user does not have access to that file. Also I like to think I understand `sudo` well enough. It did strike me as odd as I have never had to run it before while making git config edits. Could you also tell me how I tagged the question wrong? Would this be more applicable in the SuperUser board? – FRALEWHALE Apr 24 '22 at 12:11
  • 1
    @FRALEWHALE "*`warning: unable to access '/home/USERNAME/.gitconfig': Permission denied` Which is obviously a permissions issues but I am not sure how my local user does not have access to that file*" Very easy — you had used `sudo` before and thus changed the ownership of the file. The fix is `sudo chown USERNAME .gitconfig` or even `sudo chown -R USERNAME $HOME`, not `sudo git`. – phd Apr 24 '22 at 12:49

1 Answers1

2

To exand on the comment, git config --global do modify ~/.gitconfig, which is /home/<you>/.gitconfig.

That differs from sudo xxx, which executes command as root.
root home folder is /root.
And /root/.gitconfig was not modified by your initial git config commands.

In general, not using root, is possible, is a sensible route to follow.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250