0

When you push local changes to GitHub, and on the terminal, git gives you the following error on push:

remote: Permission to someorg/somerepo.git denied to someuser.

...where is someuser being read or derived from? Which config file?

smeeb
  • 27,777
  • 57
  • 250
  • 447

1 Answers1

1

where is someuser being read or derived from? Which config file?

When you connect to GitHub for push, you must authenticate yourself. There are several ways to do that and you have not shown which one you are using. (Note that other connections to GitHub may require authentication as well, depending on whether the repository is public.)

If you are authenticating over https://, Git will use various credential helpers, which may store user names and/or passwords. You can configure which credential helper to use, including the "cache" and "store" helpers, which use different additional data. Note that the available set of credential helpers varies based on your underlying operating system as well.

If you are authenticating over ssh://, you always ask GitHub to use the user name git@github.com, and the actual user ID is determined by GitHub based on the ssh key you provide. Each key has a (single) user associated with it.

[Edit to add] Use git remote show origin to show the fetch and push URLs for origin:

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:path/to/repo.git
  Push  URL: git@github.com:path/to/repo.git

If the URL begins with git@github.com: or ssh://git@github.com/, you are using ssh. If the URL begins with https://github.com/, you are using https.

For more basics and links, see the GitHub setup help page.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks @torek (+1) the exact command that is failing is `git push --set-upstream origin name-of-my-feature-branch`, so I'm not sure whether I'm pushing via HTTPS or SSH, **how can I tell**? I *can* say that I cloned via HTTP (`git clone https://...` etc.) if that helps any. Thanks again! – smeeb Nov 03 '17 at 18:31
  • 1
    @smeeb: If you initially cloned via https and have not configured any alternative URLs, you will be pusing via https as well. In this case, follow the "configure which credential helper to use" links and/or do searches for "git credential helper". Note, by the way, that when clicking on GitHub help links, it looks like they sniff at your browser OS and direct you to pages specific to that OS. – torek Nov 03 '17 at 18:41
  • Thanks again @torek (+1 again), last question: if I'm not specifying `someuser` in my push, where is Git/GitHub looking that info up? In other words, why is my error "`remote: Permission to someorg/somerepo.git denied to someuser.`" instead of "`remote: Permission to someorg/somerepo.git denied to some-other-user`"? Thanks again! – smeeb Nov 03 '17 at 18:44
  • 1
    Again, it's likely coming from your credential helper. I don't know which OS you have and which Git version you're using (and for many of those pairings I wouldn't know which file(s) if any that implies - I could do a web search, e.g., "git credential helper default windows version 12345" but you can do the same web search!). I always use ssh with GitHub myself, as I like this method better. – torek Nov 03 '17 at 18:49
  • This just isn't making sense to me: I cloned the repo via HTTPS but I am **not** being prompted for username/password when I go to push, it just fails with that error message. So how is that possible?! Actually, how about this: **How can I force git to prompt me for a username/password on each push for HTTPS?** I see that the `credential.helper` command can take several values (`cache`, `store`, etc.) but I don't see examples of resetting it to the default (where it prompts you to authenticate every time). Any ideas? – smeeb Nov 03 '17 at 19:02
  • If you're on Windows, try https://stackoverflow.com/q/15381198/1256452 - I don't use Windows and can't verify anything in these answers (note that there are many), but it seems likely. If you're on OS X, try https://stackoverflow.com/q/11067818/1256452. If you're on Linux, I don't think you should be encountering this problem at all, so I'm guessing that you're probably on Windows or OS X. – torek Nov 03 '17 at 20:27
  • Wow! That was it. I'm on OSX and going into **Keychain Access* I saw several login keys for `github.com` I erased them all and now I'm explicitly being asked for username + password, which is good enough for now. Thanks so much! – smeeb Nov 04 '17 at 00:32