1

I have a project which I want to use a different user.name (leeyuiwah), which is different to the global value leeyuiwah-sl), to talk to a certain repo in github.com. I have already updated the project's .git/config but then my command got this error

$ git push -u origin master
remote: Permission to leeyuiwah/brti.git denied to leeyuiwah-sl.
fatal: unable to access 'https://github.com/leeyuiwah/brti.git/': The 
requested URL returned error: 403

I ran this and the settings seem to be right:

$ git config --list | grep -E -e "user.*name"
credential.username=leeyuiwah
user.name=leeyuiwah

But then I realized I had a config file used by SourceTree that stored the wrong name

$ find . -type f | xargs grep leeyuiwah-sl
./.git/sourcetreeconfig.json:      "Username": "leeyuiwah-sl",

So I think I could just edit that JSON file. I did that but it did not help.

Now I am stuck. Any suggestion?

Update

More info as per comment:

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/leeyuiwah/brti.git
  Push  URL: https://github.com/leeyuiwah/brti.git
  HEAD branch: (unknown)

And

$ git config --list --show-origin | grep leeyuiwah
file:.git/config        
remote.origin.url=https://github.com/leeyuiwah/brti.git
file:.git/config        credential.username=leeyuiwah
file:.git/config        user.name=leeyuiwah
file:.git/config        user.email=leeyuiwah@gmail.com
leeyuiwah
  • 6,562
  • 8
  • 41
  • 71
  • What does `git remote show origin` say? – Christoph Jan 10 '19 at 17:10
  • @Christoph -- Thanks for helping me. See my update on the question. The output looks normal to me. – leeyuiwah Jan 10 '19 at 17:12
  • Perhaps a [duplicate](https://stackoverflow.com/q/39142102/5784831)? – Christoph Jan 10 '19 at 17:17
  • I am not sure. In my case, git seems to be confused with the two usernames that I have -- `leeyuiwah-sl` vs `leeyuiwah`. Even I seems to have edited the config file correctly, somehow it still picked up the wrong username. – leeyuiwah Jan 10 '19 at 17:20
  • But then it should also complain when you use the `git remote show origin` command! What about [that](https://stackoverflow.com/a/42787432/5784831)? Perhaps you could share the result of `git config --list --show-origin`? There can be only one valid login (user / password) for a repo. – Christoph Jan 10 '19 at 17:23
  • @Christoph -- The repo is public. So as a different user I think I still can read it. Also, I looked at your other link and ran the command `git config --list --show-origin` suggested there. (The output is added to the question) Again, the output looks normal to me. Thanks anyway! – leeyuiwah Jan 10 '19 at 17:28

1 Answers1

1

I can only guess, but this was too long for a comment anyway. My git config --list --show-origin looks like this

file:"C:\\ProgramData/Git/config"       core.symlinks=false
...
file:"C:\\Git\\mingw64/etc/gitconfig"   user.name=my name
file:"C:\\Git\\mingw64/etc/gitconfig"   user.email=my.name@domain.com
file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager
...
file:.git/config        branch.master.remote=origin

There are 3 different config files. The last entry if from the local repo. As I am working on windows with only one name, there is only one user.name, ... See here for further details.

If you cannot find different user.names in different config files in your case, something must be wrong (I guess). In other words I would expect something like

file:"C:\\Git\\mingw64/etc/gitconfig"   user.name=my name
...
file:.git/config        user.name=my second name
...

I hope that helps...

Christoph
  • 6,841
  • 4
  • 37
  • 89
  • Thanks! In my case, I seems to have made that only one user.name (`leeyuiwah`) is in all the config files, and my `git config --list --show-origin` has confirmed that, but I am still getting the error. – leeyuiwah Jan 11 '19 at 16:42
  • @leeyuiwah But then it is obvious, that "Permission to leeyuiwah/brti.git denied to leeyuiwah-sl."! There is only leeyuiwah. – Christoph Jan 11 '19 at 16:47
  • I am confused now. My remote repo is created by `leeyuiwah` and I want to push my local content to that remote, also using `leeyuiwah`. I don't understand where git picks up `leeyuiwah-sl` in this process. The only file under that directory that still has the string `leeyuuiwah-sl` is `.git/sourcetreeconfig.json`, but even if I removed this file, git still picked up the wrong user.name `leeyuiwah-sl` – leeyuiwah Jan 11 '19 at 16:52
  • You're confusing me ;-) Please go through the remotes, the users what you have and what you expect - step by step. – Christoph Jan 11 '19 at 17:08
  • Would this be a confusion due to `ssh-agent`? I may have set up that for `leeyuiwah-sl` (the user.name that should NOT be used). How do I check? – leeyuiwah Jan 11 '19 at 17:11
  • Perhaps start with a new `clone` and document the process of setting up the origin... – Christoph Jan 11 '19 at 17:17