With Git, version 1.9.3 on Fedora Linux, version 20, I am querying for example the user's name like so:
git config user.name
# Foo Bar
But when I try to change it like so:
git config user.name 'Bar Foo'
I get the following error:
# error: could not lock config file .git/config: No such file or directory
In accordance to the "XDG Base Directory Specification" (http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and the "FILES" section of the git-config(1) manpage I placed my Git config file under "$XDG_CONFIG_HOME/git/config"
.
Please note that the "XDG_CONFIG_HOME
variable is set to "$HOME/.config"
and the GIT_CONFIG
variable is unset in my environment.
I am aware that the "FILES" section of the git-config(1) manpage states: "If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used."
But then Git should ignore the "$XDG_CONFIG_HOME/git/config"
file consistently, i.e. while reading and writing.
Am I missing something?
The git config command is a convenience function that is used to set Git configuration values on a global or local project level. These configuration levels correspond to . gitconfig text files.
Git stores all global configurations in . gitconfig file, which is located in your home directory. To set these configuration values as global, add the --global option, and if you omit --global option, then your configurations are specific for the current Git repository. You can also set up system wide configuration.
config file in the Git directory (that is, . git/config ) of whatever repository you're currently using: Specific to that single repository. You can force Git to read from and write to this file with the --local option, but that is in fact the default.
Try opening it and see do this file look like this. Try setting global config through command line by- git config --global user. email "[email protected]" It automatically set the . gitconfig in the directory it needed.
You're trying to set it locally (in .git/config
) rather than globally (in the XDG config in your home directory).
The error occurs because you're not actually in a repository. It's a bit of a bogus error message but I can repeat it:
$ cd /someplace/with/no/repo; git config user.name boo
error: could not lock config file .git/config: No such file or directory
As Biffen already mentioned in a comment, you need to add --global
.
As VonC notes, the misleading error message is changed to something sensible as of git version 2.8.
Note that, if you forget --global
, the error message will be more explicit with git 2.8 (March 2016).
See commit 638fa62 (24 Feb 2016) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit d3faba8, 26 Feb 2016)
git config
: report when trying to modify a non-existing repo configIt is a pilot error to call
git config section.key value
outside of any Git worktree.
The message
error: could not lock config file .git/config: No such file or directory
is not very helpful in that situation, though. Let's print a helpful message instead.
So at least now, you know when a git config
is done outside a repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With