rstudio git commit not associated with github account

I am using RStudio for package development. I have github and git set up on my machine and i can push/pull etc. no problem via rstudio and the command line. (On a windows machine)

What i have noticed is that when i push from the command line my github profile is associated with the commit. But when i push through rstudio i get the octocat symbol indicating my commit is registered but it is not associated with my account.

i have checked my global git setting $ git config --global --list and my user name and password are my github username and noreply email. That is good.

So it appears Rstudio may be using some local settings over the global settings which is causing the problem. I have also created brand new repos and the same issue exists.

Has anyone experienced this? Has anyone advice on how to remedy this?

Thanks
Andy

1 Like

so it appears that the local user.name and local user.email have not been set (they are missing). They have not been inherited from the global settings when a project is set up in Rstudio. How can i change this?

if i set
$ git config --local user.name "myname" and corresponding email then all is fine in Rstudio.

However i have many repos. Surely i can't be expected to do this manually for each project!

thanks

Check out happygitwithr.com

Also the Git and GitHub family of functions in the usethis package:

2 Likes

Thanks Mara,
i have read this but it doesn't answer the question as to WHY rstudio is ignoring global settings (where a user name and email is provided) and choosing to to default to local settings (where both are absent).

I shouldn't have to set name and email locally to every project, and i dont want to.

None of my colleages have this issue

Understood. I'm not sure why that would be happening. If you go into global settings outside of a project, are your Git/SVN options set up?

Also, if you have the development version of usethis installed, you should be able to run usethis::git_sitrep(), which might give some useful information.

Also try setting usethis::use_git_config(scope = "user").

Here are my settings


(I'm on a PC)

It looks like my .gitconfig (global) file is located in c:~. Git Bash knows to look there since my commits from the command line are associated with my Github account.

Whereas Rstudio is looking for it in C:\users\myname (and hence returns an unknown user and email) since it's not there!

Now i could just copy the file, but that just doesn't seem right. It would be better to point Rstudio to it, but i am not sure this is possible. I'm also not quite sure how this happened in the first place.

Does this make sense?

From the Happy Git with R section on making sure RStudio knows where your executable is, it looks like your setup is typical of Windows (so that's good). I'm not sure what the best suggestion is with respect to having your .gitconfig global be so, well, global (i.e. outside the user directory).

There's a discussion on this here:
https://support.rstudio.com/hc/en-us/community/posts/203180856-Where-does-RStudio-look-for-the-global-gitconfig-file-

It sounds like symlinks might not work on Windows, but I'm not a windows user, so I'm not sure if that's still the case.

This suggests mklink should work:

What do you get if you run:

Sys.getenv("HOME")

What about if you run the following from the terminal inside RStudio:

git config --global --list

Here's the thread where Jenny explored this in usethis:

yep, read all of those. This is how i got to asking this question. Not happy about any of the "solutions"

  1. linking is a bit of a hack
  2. setting each local projects email and username is inefficient
  3. copying the .gitconfig file to windows home (default for Rstudio) leaves you with 2 copies to update. Not good practice

Sys.getenv("HOME") is c:~
Sys.getenv("USERPROFILE") is c:\users\myname

Hence the problem. Rstudio looks in the wrong place.

Would be better if rstudio had a field in global options to point to the global gitconfig.

@mara invited me to chime in here.

RStudio just shells out to Git, so it's not accurate to say that RStudio is looking in the wrong place. That is, RStudio is not explicitly looking anywhere for your gitconfig. It calls Git and, as a consequence, user-level Git config is found (or not).

The question is how can your personal use of command line git successfully find your user-level gitconfig, but RStudio's use of command line Git cannot.

What do you see if you run git config --global --list from a terminal running inside RStudio?

FWIW my impression is that creating the suggested symlink(s) so that your user-level config also appears in very conventional places is a reasonable thing to do here. Alternatively, why is your user-level Git config in this specific place? Are you willing to put it somewhere that is more conventional?

1 Like

This link, which @mara also included, is very handy for an in-depth deep dive on the path to your git config. Execute that from various places to help figure out why you're seeing different behaviour with different ways of invoking Git:

https://www.onwebsecurity.com/configuration/git-on-windows-location-of-global-configuration-file.html

1 Like

Thanks @jennybryan for joining. Thanks @mara for asking. This certainly is puzzling.

As i mentioned earlier (2nd comment) that there is no local username or email. Here are the contents of .git/config under a local project. All my projects are the same with the exceptions of ones where i have manually set the user.name and user.email

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://github.com/user/test.git
fetch = +refs/heads/:refs/remotes/origin/
[branch "master"]
remote = origin
merge = refs/heads/master

which of course is the same as $git config --list --local.

From the terminal inside Rstudio

$ git config --global --list
fatal: unable to read config file 'C:/Users/myusername/.gitconfig': No such file or directory

because it is in c:/~

I am not sure what you mean when you say "user-level" gitconfig. Do you mean local .git/config? If so then i am not sure (outside of rstudio) command line git is looking for a local config because if it was it wouldn't find a user.name or user.email field. Unless it looks, finds nothing, so defaults to global as defined in the link you sent.

"However, when you're using a (Bash) shell under MSYS2 or Cygwin, HOME under that shell is %HOME% . The global config file will be read from $HOME/.gitconfig"

But what is confusing is that the article also says
"When using the Windows command shell, batch scripts or Windows programs, HOME is %USERPROFILE% . The global config file will be read from %USERPROFILE%\.gitconfig" But that isn't the case since i can commit to github and my user.name and user.email are used

In Git Bash
$ git config --list --show-origin | awk '{print $1}' | uniq
file:"C:\ProgramData/Git/config"
file:C:/Program
file:C:/~/.gitconfig

This really is quite confusing. The more i am reading the more confused i am becoming.

Not sure what you are referring to with 'this specific place", and not sure what you mean by "more conventional". I haven't deliberately put anything anywhere, at least not knowingly! Everything got put where it is right from the installation.

Anyway, i apologize for the formatting of this, and its length :wink: and thanks for helping out. It is greatly appreciated

I believe this is the more conventional setup to which @jennybryan was referring, with "this specific place" being the current location of your global .gitconfig. Obviously it works for you, since it works in the shell, but many programs operate in a user-level environment. It's global to you as a user, not to the system.

If you want/need to keep your .gitconfig where it is, then the options are as you listed earlier (FWIW, the mklink strategy sounds best to me).

You can certainly file a feature request in the GitHub repo:

So if i didn't want it there and wanted in in the "more conventional" setup. How would i do that? Presumably i couldn't just move it manually.

@jennybryan knows infinitely more about this than I do, so I'd hold off on making any changes based on my advice.

That said…

From re-reading the Git on Windows article, it sounds you can have .gitconfig in more than one place: you're really stashing your username, email, credentials or ssh setup as a convenience. So, one option would be to just set up a user-level gitconfig.

Again, I'm not a Windows user, but the section below makes it sound like you might need .gitconfig to be above the user level for MSYS2 or Cygwin (I don't know what they are, but…). The author of this article also ultimately ends up linking them, so that might be better practice.

This is the tricky one. Basically, it depends on what the binary or environment considers the HOME directory.

When using the Windows command shell, batch scripts or Windows programs, HOME is %USERPROFILE% . The global config file will be read from %USERPROFILE%\.gitconfig

However, when you're using a (Bash) shell under MSYS2 or Cygwin, HOME under that shell is %HOME% . The global config file will be read from $HOME/.gitconfig

You can do the user-level setup with usethis, but I'm sure you can do it other ways as well.

Instead of making a copy of .gitconfig you can make a new .gitconfig file in C:\users\myname with the following content:

[include]
    path = /c/.gitconfig

The new .gitconfig file will then link to the original, and you only have to keep the original up-to-date.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.