'Change Git user in IntelliJ IDEA

My IntelliJ IDEA was used by another user and when I try to push to Git, I was asked a password of this user.

How can I change user in my IDEA? I tried to change global Git user, but it is not working.



Solution 1:[1]

  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 below code.

    [user]
          name = username
          email = [email protected]
    

Solution 2:[2]

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"

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

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

Solution 6:[6]

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.

Solution 7:[7]

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!

Solution 8:[8]

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 ;-)

Solution 9:[9]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BUY
Solution 2 Pratik Chaudhari
Solution 3 user4519506
Solution 4 Manishh
Solution 5 Codeversum
Solution 6 Subhrajit Sadhukhan
Solution 7 Sergey Kolosov
Solution 8 eventhorizon
Solution 9 Joman68