6

git: git version 2.10.1 (Apple Git-78)
macOS: 10.12.3


I am (was) having some issues with git, everything committed locally and then pushed up to GitHub is (was) not referenced in my account but rather committed by an unknown user.

I googled some online, as I always do, and came to this conclusion. The git config had been messed with. (Prev commits are fine etc.)

Naturally I tried setting my email in the git config to match the one on GitHub, this way GitHub would automatically notice the (new) commits are mine and everything would be fine..

So I ran

git config --global user.email <my-email@email.com>

Without success... The following error was returned to me:

error: could not lock config file /Users/<user>/.gitconfig: No such file or directory

I tried to reinstall/update git by downloading the latest version here.

Running git config --global -l to list all of the configs returns the following error:

fatal: unable to read config file '/Users/<user>/.gitconfig': No such file or directory

terminal screenshot


Conclusion

The file does not seem to exist. As you can see in the screenshot. Reinstalling git via their website did not initiate the config file.
I have no clue what to do...


Other posts:
I tried resolving this issue by going trough other related answers etc. However this did not help me resolve this issue. I think my case is a little more specific than most cases...


update

Tried to create the folders: update screenshot

  • 3
    You made `.gitconfig` a symbolic link to a file that does not exist. That's not so bad, but I suspect you made it to a file that does not exist *within a directory that also does not exist*, and that makes it impossible for programs like `git config` to *create* the file. (If so, the cure is to make the parent directory.) – torek Feb 05 '17 at 15:07
  • @torek See the update :) – Jesse van der Pluijm Feb 05 '17 at 15:26
  • Huh, well, that's weird. Can you create an empty file there manually? – torek Feb 05 '17 at 15:37
  • [this](http://stackoverflow.com/questions/16283280/how-to-locate-the-git-config-file-in-mac) states that the location should be `~/.gitconfig`. This is the home directory so it should be (and is) there. So how can I undo the symlink to `/Users//dotfiles/git/.gitconfig`? – Jesse van der Pluijm Feb 05 '17 at 15:38
  • @torek running `/Users/Jesse/dotfiles/git/.gitconfig` fails: `touch: /Users/Jesse/dotfiles/git/.gitconfig: No such file or directory` – Jesse van der Pluijm Feb 05 '17 at 15:39
  • You can remove any symbolic link with ordinary `rm` (e.g., `rm ~/.gitconfig`). The odd thing here is that if the symlink points to a valid directory, Git should be able to create a new file there if needed, unless there is a permissions issue, and if there is a permissions issue, you should get a different error. – torek Feb 05 '17 at 15:39
  • @torek So this is really weird huh. We'll glad to know it's not just my usual stupidity here. Hopefully I'll be able to resolve this issue though – Jesse van der Pluijm Feb 05 '17 at 15:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134903/discussion-between-torek-and-jesse-van-der-pluijm). – torek Feb 05 '17 at 15:43

1 Answers1

19

Try

rm ~/.gitconfig
touch ~/.gitconfig

to remove the bad symlink and create a new config file.

Then re-run you command to create the setting:

git config --global user.email <my-email@email.com>
Harald Nordgren
  • 11,693
  • 6
  • 41
  • 65