106

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.

11 Answers 11

156
  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 = [email protected]
    
7
  • 1
    In the base directory of my project, I don't find this file. Adding it did not help. Commented May 10, 2021 at 4:13
  • 1
    @vishvAsvAsuki If the directory '.git' is not found, then this code not cloned from github. Please make sure that you are cloning your project from github repo. Commented May 12, 2021 at 1:17
  • Ah ok- I was probably looking under a git submodule, instead of the parent. Commented May 13, 2021 at 1:18
  • 1
    you can do it more simple,,, 1. Go to the base directory of your project. 2. git config user.name "yourusername" git config user.email "[email protected]" Commented Jun 29, 2021 at 6:23
  • I think that Bitbucket users do not have the name and email fields in the .config file, instead we need to change the url field.
    – Cohensius
    Commented Feb 14, 2022 at 13:26
43

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"
2
  • 27
    The OP was asking how to change it in IntelliJ, not globally. Commented Feb 13, 2018 at 16:30
  • 1
    Similarly there is user.email parameter, which could be changed as well.
    – KarelHusa
    Commented Oct 27, 2021 at 13:20
21
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.

1
  • 2
    How would you format the url if the username you have is an email address? Im trying to set the username for using google's repos and they use your email address as a user name. Ive tried [email protected]@source.developers.google.com..... but that failed. Commented Sep 4, 2018 at 20:17
19

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

1
  • 6
    Should be .git/config file Commented Oct 17, 2017 at 21:12
13

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.

8

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

3
  • 2
    Not Github, Git. I have bitbucket repo Commented Feb 2, 2015 at 10:46
  • then you should have bit bucket setting under Setting tab,
    – dReAmEr
    Commented Feb 2, 2015 at 10:50
  • 1
    I do not have settings for bitbucket in Idea, just need to find where to change user Commented Feb 2, 2015 at 11:22
2

I did not quite like the previous answers, since one user was used for all projects, and it is not necessary to change it everywhere when changing the password.

C:\Users\{USER}\AppData\Local\JetBrains\IntelliJIdea2022.2\vcs-users\

Deleting the contents of this folder worked for me. I'm not entirely sure that this folder is responsible for storing information about git users, but judging by the name, this is it. Before deleting, just in case, make a backup of the folder.

P.S

C:\Users\{USER}\AppData\Roaming\JetBrains\IntelliJIdea2022.2\options\vcs.xml

It looks like just logins for different projects are stored here. But no password.

1

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

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

0

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

-3

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

1
  • 3
    Not Github, Git. I have bitbucket repo Commented Feb 2, 2015 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.