Change Git user in IntelliJ IDEA

JavaGitIntellij Idea

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

  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 - Java

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 - Java

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

Solution 4 - Java

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 - Java

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 - Java

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 - Java

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 - Java

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 - Java

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

Solution 10 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser4519506View Question on Stackoverflow
Solution 1 - JavaAmaresh NarayananView Answer on Stackoverflow
Solution 2 - JavaRuwenView Answer on Stackoverflow
Solution 3 - Javauser4519506View Answer on Stackoverflow
Solution 4 - JavaKalinkaView Answer on Stackoverflow
Solution 5 - JavadReAmErView Answer on Stackoverflow
Solution 6 - JavaSubhrajit SadhukhanView Answer on Stackoverflow
Solution 7 - JavaSergey KolosovView Answer on Stackoverflow
Solution 8 - JavaeventhorizonView Answer on Stackoverflow
Solution 9 - JavaJoman68View Answer on Stackoverflow
Solution 10 - JavaCodeversumView Answer on Stackoverflow