在 IntelliJ IDEA 中更改 Git 用户

我的 IntelliJ IDEA 被另一个用户使用,当我试图推到 Git 时,我被要求输入该用户的密码。

我如何在我的 IDEA 中更改用户? 我试图更改全局 Git 用户,但它不工作。

162665 次浏览

Go to File -> Settings -> Version Control -> GitHub and enter your Login and Password there.

Go to below link.

File-->Settings--->Version Control -->GitHub

If you need to connect to Bitbucket, you need to change the host to bitbucket.org

I found a solution myself: just find hidden .git file in your project root, open it, and change user.

Just change in terminal in IntelliJ Idea an URL of your project. Put yours instead of ${urlToYourProject}.

git remote set-url origin ${urlToYourProject}

Then update project (Ctrl+T). And you'll see the dialog where you can set your credentials.

Don't forget that you can use other remote name instead of origin!

  1. Go to the base directory of your project.

  2. You will find a hidden directory called .git. Enter into it.

  3. There you will see a file called config. Add the following code.

    [user]
    name = username
    email = username@domain.example
    

You can change it global via any of the 2 options.

  1. "Git Bash" which comes with the git installation package.
  2. In IntelliJ View > Tool Windows > Terminal (Alt + F12).

Use command :

git config --global user.name "John Doe"
Go to VCS -> Git -> Remotes

There you can edited your git remotes by changing user in the URL https://user@serc-bitbucket.

In your next Push you'll be prompted to a dialog to enter your password, and in the next your credientials.

Update the user or the repo URL (depends what you really want to change) in you project by entering the .git folder (in your project) and modifying the "config" file respectively.

When using azure devops I needed to change the repo url which contained the token I had to change ;-)

I had faced similar challenge with changing my user, when I was pushing files directly from IntelliJ Idea and though the files were updated in GitHub it was being updated from a different account.

Turns out there's a file called .gitconfig in windows where the user name and email is stored.

C:\Users\<USER_DIR>\.gitconfig


[user]
name = <USERNAME>
email = <EMAIL>

Changing the email here changed my account.

Here the blog & a stack overflow question I used for reference.

If you are on a Windows machine and git is using the Windows credential manager, then you can change the username and password in the credentials manager:

windows credentials example

To check if git is using the windows credential manager:

$ git config credential.helper
!"C:/dev/git-2.32/mingw64/libexec/git-core/git-credential-wincred.exe"

And to check if IntelliJ git is using the credential manager: intellij git settings