git-autoconfig icon indicating copy to clipboard operation
git-autoconfig copied to clipboard

git-autoconfig: Failed to get git repository root.undefined

Open vallamost opened this issue 5 years ago • 7 comments

What can cause this error message? I just installed the plugin and I am trying to 'set' the config.

In my workspace I have numerous folders containing .git folders in them so I don't know where I can define the repository.root

vallamost avatar Nov 08 '19 07:11 vallamost

Make sure you open the folder path directly rather than a folder in a workspace.

thomasluxton avatar Mar 21 '22 15:03 thomasluxton

Make sure you open the folder path directly rather than a folder in a workspace.

What do you mean by this? I have the folder expanded in the workspace and have ran git init and can see the .git folder, but I get the same error when trying to set local config.

chaoscreater avatar May 31 '23 01:05 chaoscreater

Hi, I must have come across the same error and by the looks of it, just opening that one folder in VSCode (not multiple folders in the workspace) which seemed to fix the issue. However, since it's been over a year, (and didn't realise there were 4 confused faces!), I can't remember more about the error unfortunatly.

However, if it helps and you are happy to use access keys instead, you can embed the access key into your local git folder which allows you to use different credentials for each folder, without using git-autoconfig:

CD D:\GIT[LOCAL FOLDER] git remote set-url origin https://[USERNAME HERE]:[ACCESS KEY HERE]@github.com/[Repo HERE]/[REPO NAME].git git config --global credential.helper store

I've been doing this for over a year now. Hope this helps.

thomasluxton avatar May 31 '23 11:05 thomasluxton

That only works for Github though. What about other repos, e.g. Azure DevOps?

And if you're going to modify the .local config, you might as well just manually add the user config in there, which is basically what git-autoconfig is doing. If you add it manually, the issue is fixed.

chaoscreater avatar May 31 '23 11:05 chaoscreater

Seems like valid points. I didn't find much benefit for git-autoconfig for me personally, I was happy to add it in manually in the end, but didn't know how to do that at the time. Hopefully my contribution might help some wanderer.

thomasluxton avatar May 31 '23 11:05 thomasluxton

Or just use alias. In your global gitconfig (located under C:\Users\username.gitconfig), add this block to the very top:

[alias]
	GitHub-Personal = !git config --global user.name 'Personal GitHub' && git config --global user.email [email protected]
	GitHub-Work = !git config --global user.name 'Work GitHub' && git config --global user.email [email protected]

then just run:

git github-personal or git github-work

and it'll switch aliases to use the correct account context. Since this is defined in the global git config, you only need to configure it just once and in any of your projects, you can switch configs easily using the command above. You don't need to even set a local config or set access key PER project folder.

However, I still much prefer having a local config per folder, it's more granular and gives more control.

chaoscreater avatar May 31 '23 11:05 chaoscreater

Thanks for the input. I think I found when setting the usernames as such, each one required authentication and I seem to remember having a hard time authenticating to both repositories using two different usernames at the same time. It was not seamless as such. Often a folder would refuse to sync where I had to essentially switch the authentication round and that was also confusing. I found this problem went away when I started using the access keys, but nether the less, when I comes across this again, I'm sure to take another look at it. Thanks for contributing to the thread.

thomasluxton avatar May 31 '23 11:05 thomasluxton