Set GitHub user per repo

已回答

I have started working with a new client and I want to use the GitHub user that they created for me to access their repos. This is separate from the GitHub user that I use for other clients.

I cloned their repo and when I opened it, it asked me which GitHub user to use. It appears that IntelliJ updated my ~/.gitconfig with my new name and GitHub email (which was unexpected).

Now, I cannot update the repo from within IntelliJ IDEA. I get an warning “Update caneled” along with the error

  remote: Repository not found.

I assume that this is because the wrong GitHub credentials are being used, since the repo demonstrably exists.

Is there a way to manage this within IntelliJ IDEA? Some way to set which set of credentials to be used for a given repo?

I'm using IntellJ IDEA 2023.4.6

0

IDEA should never modify your config file.

How did you add the account?

This error also occurs if you have authorized your github account via browser but your organization did not approve, please see: https://docs.github.com/en/organizations/managing-oauth-access-to-your-organizations-data/approving-oauth-apps-for-your-organization

0

I don't really know how it got added. Normally, when I run the first git command in a new project, IDEA presents me with a list of GitHub users and asks me which one to use. I don't know how it gets this list, since ~/.gitconfig seems to only list one user.

In this case, I selected the new user. I switched back to an old project and pushed changes. The git log showed the new user name. That's when I checked ~/.gitconfig and saw that it had been updated. If as you say, IDEA does no update this, then it must have gotten changed some other way.

But that doesn't help me with my initial question, which is how can I set one GitHub user for a specific repo, while using my other user in other repos?

BTW, the new user is a member of the expected organization.

0

Git actions performed via IDE and Github plugin are 2 separate entities. 

When you login via plugin, your token is saved per Settings | Appearance & Behavior | System Settings | Passwords settings and you are able to view PRs, add comments etc and this is performed via plugin via Github APIs.

Git actions, however, pushing project, pushing commits etc are performed via command line using git commands. (you can see these commands sent by IDE in console tab that pops up) and authentication can be performed in two ways:

1) In Settings | Version Control | Git, if you have “Use credential helper enabled”, then password is saved per your credential helper configuration (which is usually defined in your local git config, example “credential.helper=osxkeychain”) and in this case you can use “https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-personal-account/managing-multiple-accounts#contributing-to-multiple-accounts-using-https-and-personal-access-tokens” to set everything up. 

2) If “Use credential helper” is disabled, then IDE will use the password saved by  Settings | Appearance & Behavior | System Settings | Passwords settings via script (git askpass). 

 

Now I am unsure how the errors happens on your side. 

Can you share the output of the console? 

Can you share your global git config and local git config of the project? 

0

请先登录再写评论。