Git: Dealing with multiple Git accounts
- 2 minutes read - 267 wordsTips & tricks …
… plus a few reminders for things I often need to look up
This is another annoying thing I always forget about related to Git and multiple Git credentials. If you have multiple Git credentials and simply clone a repo without specifying any particular credentials, it will use your global default credentials. You can view them with:
git config list --global
For me this is my employer credentials. However, I also have personal credentials and often credentials for my current client project.
However, sometimes if I use Git -> Update Project in Rider (i.e. git pull) it will
use the wrong credentials and I get a 403 response or I will get prompted to select which account to use:

It then remembers this for the rest of the session but closing and reopening the project in Rider means it will do it all over again.
Now, and I haven’t quite worked this out yet, sometimes from the command-line (git pull) things work out fine; it doesn’t
prompt in the first place, it uses the correct credentials and it remembers what to do next session.
This is for GitHub, which I use most, and there is more info behind the Why am I being asked to select an account? link in the dialog above. It seems “it’s complicated”, but I think this is a Rider thing rather than a Git thing on its own.
Anyway, to keep all routes happy you can do this:
cd /path/to/repo
git config --local credential.username "YourSpecificUsername"
git config --local credential.useHttpPath true
and things get remembered, even for Rider. Wahoo!