0

I have two GitHub usernames (one personal, one related to my job), and both have different, mutually exclusive private repos associated with them.

This causes problems every time I want to, for example, switch from executing commands on a personal private repo to a work-related private repo (or vice versa). When I try to do this, I always get permission-denied errors in the Windows Git terminal.

To provide a quick example, if I tried to execute a git pull as the "wrong user", I get the following error:

remote: Repository not found.

What do I need to do to avoid these permission-denied errors? I simply want to be able to perform a bunch of commands on one repo and then essentially switch to another GitHub user in the Windows Git terminal so that I can freely execute commands on a different private repo as a different user.

Thanks.

Hugo y
  • 1,421
  • 10
  • 20
HartleySan
  • 7,404
  • 14
  • 66
  • 119
  • 1
    Possible duplicate of [Multiple GitHub Accounts & SSH Config](https://stackoverflow.com/questions/3225862/multiple-github-accounts-ssh-config) – phd Mar 26 '18 at 02:39
  • phd, thanks for the response. Does that apply to using Windows Git terminal as well? Thanks. – HartleySan Mar 26 '18 at 02:49
  • I think so. Two ssh keys, 2 git configurations, add both keys to `ssh-agent`, no need to switch at the command line at all. – phd Mar 26 '18 at 02:51
  • For https access the solution would be different if possible at all — Windows Credential Manager can store credentials for 1 user; see https://stackoverflow.com/a/48466698/7976758 – phd Mar 26 '18 at 02:51
  • I don't have any `rsa` files under `~/.ssh/`, and `ssh-add` doesn't create them. I have one file in that directory called `known_hosts`. Not sure what to do or how the answer you linked me to helps. Any advice? Thanks. – HartleySan Mar 26 '18 at 21:35
  • See [the second answer](https://stackoverflow.com/a/46257084/7976758) and [the gist](https://gist.github.com/gubatron/d96594d982c5043be6d4) it points to. See other answers there. Use `ssh-keygen` to generate 2 different key pairs (one personal, one for job), upload public keys to the corresponding accounts, use `ssh-add`… – phd Mar 26 '18 at 22:51
  • phd, appreciate all your help, but after following all the steps outlined in multiple solutions and getting all the expected success messages, I still couldn't get it set up to work with SSH. Also, like you mentioned, Windows 10 Credential Manager only allows one GH user. However, I then came across the following, which solved my problem: https://github.com/Microsoft/Git-Credential-Manager-for-Windows/issues/249. Specifically: `git config --global credential.useHttpPath true`. After that, the first time I tried to pull from each repo, it prompted me for a password, and now it's fine. – HartleySan Mar 27 '18 at 02:41

1 Answers1

0

In theory, using SSH keys, etc. to connect to my GH repos would have worked, but it was too complicated and there seemed to be 800 answers to the question, none of which seemed to work.

However, the following single command in the Git for Windows terminal solved my problem:

git config --global credential.useHttpPath true

By doing that, Git will require you to authenticate yourself once for each private repo, and after that, it'll remember the credentials for each one separately. After I did that, the issue went away.

HartleySan
  • 7,404
  • 14
  • 66
  • 119