Skip to content

Global gitconfig fails to copy to devcontainer with postCreateCommand #787

Description

Related to this issue #98 there still seems to be a problem for the global git config.

My local git config is copied, but my global git config is not. Settings that only existed in my global config like my name and email are not copied.

It seems that a default empty global git config is created when using postCreateCommand. In my case, I am running a script "postCreateCommand": "sh ./scripts/env-setup.sh"

Here is what my containers global git config looks like when using postCreateCommand:

# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
#	name = 
#	email = vscode@b97bec6ca4f1.(none)

If I change it to postAttachCommand, then an exact copy of my actual global git config file from my machine is copied correctly into the dev container.

Activity

  1. chrmarti commented on Mar 26, 2024

    @chrmarti
    Contributor

    We could ignore the empty [user] section. As a workaround you can comment out the [user] line as # [user].

  2. AvinZarlez commented on Mar 26, 2024

    @AvinZarlez
    Author

    I confirmed manually removing the global file ( or commenting out the empty user section ) does make it so the proper global file will be copied. Although that is a manual step that may be annoying/easy to miss/hard to explain to developers when making a fresh container.

    I think ignoring an empty [user] section is ideal.

  3. sdavids commented on May 4, 2025

    @sdavids

    On a related note:

    ~/.config/git/config

    [include]
      path = ~/.config/git/local
    

    ~/.config/git/local

    [user]
      name = Example User
      email = example@example.com
    

    https://git-scm.com/docs/git-config#_includes
    https://git-scm.com/docs/git-config#Documentation/git-config.txt-includepath
    https://git-scm.com/docs/git-config#Documentation/git-config.txt---no-includes

  4. KnorpelSenf commented on Nov 28, 2025

    @KnorpelSenf

    I am running into the same issue. For me, the problem was that the postCreateCommand had a non-zero exit code.

    When I added ./my-setup-script.sh || exit 0 then the global .gitconfig was made available inside the container again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions