Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Git config option when its config file is "$XDG_CONFIG_HOME/git/config"?

Tags:

git

config

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?

like image 461
Tim Friske Avatar asked Jun 12 '14 20:06

Tim Friske


People also ask

What is the git command to set configuration options?

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.

How do I apply a configuration across the entire git environment?

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.

Which is the default file option for git config command?

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.

Why git config is not working?

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.


2 Answers

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.

like image 110
torek Avatar answered Nov 05 '22 15:11

torek


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 config

It 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.

like image 29
VonC Avatar answered Nov 05 '22 15:11

VonC