5

I tried to clone a repo using GitKraken on Ubuntu, but it threw me an error "failed to open '/etc/gitconfig' - permission denied".

So I think GitKraken software needs to access a gitconfig file to get things work, and it somehow tried to access the one at /etc/gitconfig first (which is locked - I don't even know what "lock" mean), so it threw the error. After googling, I found a solution sounds rational is to type chmod 777 /etc/gitconfig to give everyone (includes GitKraken) the permission to read/write to that config file. But after doing that, it still not work (permission denied), even after a reboot. First attemption failed. Maybe it's not about permission?

I then kept googling, then I knew that there are 3 types of config files for git, which are local (located in .git/gitconfig), global (in ~/.gitconfig) and system (in /etc/gitconfig). Then I thought "aha, I could just delete the /etc/gitconfig, then Kraken will use ~/.gitconfig". And yet after deleting /etc/gitconfig, it works (I can clone my repo as expected). But I think it's just a workaround, I don't know what's the consequence of doing this (deleting system gitconfig). As I read in the document, it should first read the local one, then global, then system in order, so it should only read /etc/gitconfig if only can't find one in ~/.gitconfig, am I right? Why it isn't the case here? Or does GitKraken deliberately setting to read the config file from /etc/gitconfig first instead of the above order?

Conclude, I deleted the system gitconfig /etc/gitconfig (by renaming it to /etc/.gitconfig btw). My question is what should I do now, did I solve my problem? If yet then now I don't fully understand what's going on, please can someone explain to me?

Thanks in advance.

Error capture: capture

Loi Nguyen Huynh
  • 8,492
  • 2
  • 29
  • 52

2 Answers2

4

You can do a git config --show-origin -l to see all configuration files involved.

The /etc/gitconfig is the system-wide configuration file, always read first.
A locked file generally means another process has kept an handle on it (usual with Windows, but you might be on Linux)

You can recreate it later, even with a minimal content, just to see if the issue persists:

[color]
        diff = auto
        status = auto
        branch = auto
        interactive = true

Apparently, from the comments, the issue was how GitKraken was installed:

The second method produces a GitKraken which won't be tripped by a locked /etc/gitconfig.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you!! After reading your comment, I tried recreating `/etc/gitconfig` file with the content suggested above. But as typing `git config --show-origin -l` I only saw configurations from `~/.gitconfig` (none from `/etc/gitconfig`). After that, I tried cloning a project with GitKraken, it pop up the same error `/etc/gitconfig is locked`. One of my friends has used GitKraken too and it works just fine on his computer, he can clone projects even if there's `/etc/gitconfig`, so I guess it doesn't matter its existence, but somehow, showbody (likely me) has locked my "system gitconfig" file? – Loi Nguyen Huynh Nov 23 '19 at 08:51
  • @HuỳnhLợiNguyễn Are you on Windows? What version of Git do you have installed? – VonC Nov 23 '19 at 08:53
  • No, I'm on the Ubuntu 19.04, and my git version is 2.20.1 – Loi Nguyen Huynh Nov 23 '19 at 08:55
  • @HuỳnhLợiNguyễn Can you, for testing, upgrade to Git 2.24? (https://askubuntu.com/a/500733/5470) – VonC Nov 23 '19 at 09:05
  • I did, now I'm on git 2.24, have tried rebooting and the error is still the same. Ah, one thing I have noticed that when I typed `cd /`, I saw a lock symbol on the left of directory `/` on my terminal. But if I try typing `cd ~`, there are no locks. – Loi Nguyen Huynh Nov 23 '19 at 09:13
  • 1
    @HuỳnhLợiNguyễn Is there a difference in the way GitKraken itself has been installed (compared to your friend's workstation)? And would the clone succeed when done in command line? (`git clone ...`) – VonC Nov 23 '19 at 09:15
  • I honestly don't remember the way I installed it, I guess **from Ubuntu Software**. I asked my friend how he installed it, he said from the [official website](https://www.gitkraken.com/download). I tried doing the same, install from the website, and then there was 2 GitKrakens on my computer when tap on "Show Applications", but when I opened "Ubuntu Software-Installed", I only saw one, I deleted what I saw. After that, everything just worked, I could clone repo, there was still `/etc/gitconfig`, still a "lock symbol" on my terminal. I guess the problem was **the way I installed the software**? – Loi Nguyen Huynh Nov 23 '19 at 09:36
  • 1
    @HuỳnhLợiNguyễn I suspect the installation method was the culprit, but I don't know exactly why. I have edited the answer accordingly. – VonC Nov 23 '19 at 09:40
  • @HuỳnhLợiNguyễn Maybe a `sudo dpkg --configure -a` would have helped (https://bugs.launchpad.net/ubuntu/+source/software-center/+bug/489643/comments/2) – VonC Nov 23 '19 at 09:41
  • 1
    @HuỳnhLợiNguyễn You are most welcome. Glad you now have a working GitKraken! – VonC Nov 23 '19 at 09:45
2

I was having this same problem on 20.04.
Unfortunately the download from the gitkraken website was giving me a dependency error, so i had to use snap.
Tried removing and recreating the config, didn't work. Tried everything in the comments of the other answer, but wasn't able to resolve the problem.

Simply deleting /etc/gitconfig resolved it for me.

Taekahn
  • 1,592
  • 1
  • 13
  • 16