How can I switch Git credentials or “log in” as a different user without changing config variables?

I’ve run into this when switching between my work and personal GitHub accounts. A super clean trick to avoid messing with config variables is to embed your GitHub personal access token (PAT) directly into the clone URL like this:

git clone https://<USERNAME>:<TOKEN>@github.com/current_user/repo.git

If you’ve already cloned the repository, just update the remote URL like this:

git remote set-url origin https://<USERNAME>:<TOKEN>@github.com/current_user/repo.git

This approach avoids credential caching, letting you push as the correct user just for that session. Git won’t store the credentials unless you’re using a credential manager, so it’s a quick, session-based fix.