Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Sharing Git credentials with your container" doesn't work

What I did

  1. set the git config globally.
(local) $ git config --global user.email "[email protected]"
(local) $ git config --global user.name "Your Name"
  1. Remote-Container: rebuild Container

  2. Git commit

(Remote-Container) $ git commit -m hogehoge

Result

*** 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@aaaaaaaaaaa.(none)')

Ref

https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container

like image 897
t29mato Avatar asked Apr 17 '26 16:04

t29mato


2 Answers

I had a similar issue because I was running git config --global in postCreateCommand. I wanted to change the diff and merge tools in the container. However, my username and password disappeared from my .gitconfig. I did not understand the cause yet, but I solved the issue by adding my commands to the postAttachCommand instead.

So, in the .devcontainer/devcontainer.json, instead of:

{
  ...
  postCreateCommand": "git config --global diff.tool ...",
  ...
}

I use:

{
  ...
  postAttachCommand": "git config --global diff.tool ...",
  ...
}

I am wondering if your situation is not related. It should be useful to know your .devcontainer/devcontainer.json. Still, I hope this information is useful for other users with similar problems.

like image 149
saulotoledo Avatar answered Apr 19 '26 14:04

saulotoledo


For me I was using WSL2 on Windows with devcontainers and found that it doesn't copy .gitconf from windows but from the base Linux distro so I had to add the settings there.

So in WSL terminal I did :

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

Then these settings were shared with the devcontainer.

like image 44
Mohamed Gharib Avatar answered Apr 19 '26 14:04

Mohamed Gharib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!