简体   繁体   中英

Changing the Git user inside Visual Studio Code

The user for my Git commits has changed, but I am not able to change that inside of Visual Studio Code.

I changed the global settings in Git, but when I want to push or sync via Visual Studio Code inside my new repositories I get the error that the oldusername has not the permission to push into newrepository .

At this point it is not the permission. The change of the username did not work for Visual Studio Code. When I use the terminal I can push. It is also not a solution to allow the olduser to push to the newrepository .

I am on Windows 10. So all other tools are working, but just at Visual Studio Code I was not able to change the user.

How can I fix this problem?

我通过在 Git 中设置电子邮件地址解决了这个问题:

git config --global user.email "email@example.com"

Generally, Visual Studio Code uses the GitHub credentials from the system's credential manager. It doesn't store it anywhere in the settings. As question says, Changing the Git user inside Visual Studio Code , is not inside rather outside .

Search for or go to Credential Manager (Windows control panel) → Windows Credentials → update the GitHub password from the list.

You can view all of your settings and where they are coming from using:

git config --list --show-origin

Delete the unwanted credentials from the directory and then Visual Studio Code will ask you for the credentials next time when you perform Git operation.

1. Sign out of your current account (only if you want to switch the current account)

在此处输入图像描述

2. Change Git settings globally

在此处输入图像描述

git config --global user.email youshaarif13@gmail.com
git config --global user.name YushaBinArif3

After completing the above steps, close and reopen Visual Studio Code. The next time you will execute your Git commands, you will be asked to login via browser, make sure you open that link in a browser where your desired GitHub account is logged in.

To check/get old values:

git config --global user.email
git config --global user.name

Output:

youold@email.com
youroldgoodname

To set new values

git config --global user.email yournew@email.com
git config --global user.name yournewgoodname

Press Ctrl + Shift + G in Visual Studio Code and go to more and select Show git output . Click Terminal and type git remote -v and verify that the origin branch has latest username in it like:

origin git@github.com:DroidPulkit/Facebook-Chat-Bot.git (fetch)

origin git@github.com:DroidPulkit/Facebook-Chat-Bot.git (push)

Here DroidPulkit is my username.

If the username is not what you wanted it to be then change it with:

git add remote origin git@github.com:newUserName/RepoName.git

I had the same problem as Daniel . Setting the commit address and unsetting the credentials helper also worked for me.

git config --global user.email '<git-commit-address>'
git config --global --unset credential.helper

This could be because of the reason that the credentials are saved and you need to update those credentials and you can do that by following the below steps:

Control panelCredential Manager → under Generic credential , you will be able to see the credentials related to Git.

Try to update them. If that does not work, delete them and add new ones.

For other platforms or different versions of the operating system, you need to find out where the credentials are saved related to Git and update them.

Git Graph

You can change the git user in the Extension Git Graph easily.

  1. Go to the Extensions tab and install Git Graph .
  2. Go to the Source Control tab in the SOURCE CONTROL accordion menu.
  3. Click on the View Git Graph (git log) icon. Git Graph - 存储库设置
  4. Click on the Repository Settings icon.
  5. In the User Details section, click Edit and change the Git User Name and Email.

.git/config

A simpler solution that works with any IDE is to add the user to the .git/config file:

[user]
  name = bar
  email = bar@mail.com

There is a conflict between Visual Studio 2015 and Visual Studio Code for the Git credentials. When I changed my credentials on Visual Studio 2015, Visual Studio Code let me push with the correct Git ID.

I just signed up for a new GitHub account to create a project and I had the same issue. I resolved it by doing the following:

 $ git credential-osxkeychain erase host=github.com protocol=https > [Press Return]

When I attempted to push to my new remote repo after this, it asked me to sign in to the new account; I did that, and it worked.

From the Visual Studio Code Command Palette , select:

GitHub Pull Requests: Sign out of GitHub.

Then sign in with your new credentials.

Firstly set VS code to default editor through git like

  1. git config --global core.editor "code --wait"
  2. git config --global -e

After setting vs code to default editor , then type

  1. git config --global --list

it will show you all global configuration .

If you want to change any just type

-> git config --global -e

Vs code will open then change your user.name , email-address & any thing you set in easy manner.

Hope i solve your problem.

The quick and easy way is to sign in at https://github.com as the user you want to use, then in the lower left corner, sign-in to Github (sign off if any user is currently connected). VS Code will use the user that you are already logged in as in the browser.

在此处输入图像描述

I was facing the same issue tried multiple options but didn't work for me. Then i tried this method https://stackoverflow.com/a/39608906 and it perfectly worked for me (Thanks to Venkataramana Madugula). Hope it will help you. Visit the link and follow the steps. You just need to remove the github from the list.

From within the Visual Studio Code terminal,

git remote set-url origin https://<your github username>:<your password>@github.com/<your github username>/<your github repository name>.git

for the quickest, but not so encouraged way.

I was running into this because I had incorrectly typed my GitHub/GitLab credentials into the pop-up from Windows Credentials Manager. In Windows 10, access Credential Manager from Control Panel; you can also just search for Credential Manager in the search bar. In Credential Manager, find your Git credentials in Windows Credentials and amend to the correct version. After this, Git worked from the CLI.

Others have made suggestions about trying to trigger the pop-up again by signing out of GitHub and running git pull from the CLI, but neither of those worked for me.

在此处输入图像描述

用户操作系统打开 Visual Studio 代码必须与用户 git 相同

I tried several changes to settings, including the Windows Credential manager. In the end, I:

  1. Closed Visual Studio Code
  2. Opened PowerShell
  3. Set the credentials there, with the --global option
  4. Closed PowerShell
  5. Opened Visual Studio Code

Visual Studio Code is now happy with its Git name and email, and I'm able to push and pull!

Open Visual Studio Code

在此处输入图片说明

  1. Click Accounts icon on the bottom left

  2. select the corresponding github account and click Sign Out

Or
Choose a different account from the account list

如果您使用 mac 系统,您需要在 pc 中打开终端,而不是在 vs 代码中

HAVE AS MANY ACCOUNTS AS YOU WANT JUST SET THE CONFIG FOR THAT PROJECT

NO MORE SIGNIN AND SIGNOUT!

So there is an extension with a name git-autoconfig by shyykoserhiy .

After installing it open the command palette ctrl + shift + p . Type git-autoconfig and it will have 2 options one being set-Config and other get-Config and these both serve the same purpose which their name is conveying.

Every time you open the project in vscode it will prompt you automatically which config to use (in case of multiple accounts).

It is as easy as setting it with git-setconfig

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM