Wrong user when pushing to Github from VSCode - windows

I am new to VSCode and Github and I use Windows 10. I have 2 Github accounts, one "Private" and one "Work". I started out with "Private" but I am not using it anymore. I linked the VSCode account to "Work" and verified it has done this correctly.
Now, when I push a file from local to remote, it keeps pushing it with "Private". So I checked how to solve this and changed 2 things:
In Git bash, I typed: git config --global user.name and git config user.name, and found out it said "Private" for both. So I entered: git config --global user.name "Work" and git config user.name "Work", which changed this to "Work" for both
On my laptop, I went to Start -> Control Panel -> User accounts -> Manage Your Credentials -> Windows Credentials and removed the credentials for "Private"
I hoped these 2 actions would solve the issue, but unfortunately it doesn't. Is there anywhere else where I should change something?

I solved the issue with help from this link provided by #Abdul:
I typed git config --list, which showed an overview of the credentials cashed. There I noticed user.email was still using the email address of my "Private" account. So I typed git config --global user.email <my "work" email address> and that solved the issue - when I push now to remote it's done via my "Work" git account

The user.name and user.email have nothing to do with authentication, only commit authorship.
And Windows Credential Manager is only used for HTTPS URLs.
If your remote repository is referenced with an SSH URL, said credential manager would not be involved at all.

Related

Gitbash changing github account

I was using github account A on gitbash and I wanted to switch to B.
I deleted the credentials for github from control panel for account A and signed with B
When I run git config --list, user.email and user.name matched with account A
than I did:
git config --global user.name "AccountB'sname"
git config --global user.email AccountBemail
When I run git config --list , Now user.email and user.name matches with account B. And when I make a commit, It is seem to be with account B. So it's good.
My first question is: Is it all to do when changing github account on gitbash ?
2- why on my first git config --list run, name and email did not match even tho I updated credentials from control panel
Your GitHub credentials and your Git config are two unrelated things.
When you set user.name and user.email, what you are changing is the metadata that will be used in any commits your create. Creating commits is a local operation on your machine, and does not involved talking to GitHub or any other Git server.
When you want to connect to GitHub using a different account, you did the right thing: change your credentials for GitHub in the Windows Credentials Manager. That will not affect how commits are created on your machine, only how you will authenticate yourself when connecting to GitHub.

Easy way to switch between accounts on git in the terminal on windows?

Is there a quick way to just log out and log back in with a different account on git in cmd on windows?
I tried:
git config --global --unset user.name
git config --global --unset user.mail
git config --global --unset credential.helper
so I understand I should have been logged out with the old_user_name?
Then I used:
git config --global user.name "new_user_name"
git config --global user.email "new_email"
git push origin master
I got a massage:
remote: Permission to new_user_name/new_repo.git denied to old_user_name.
fatal: unable to access 'https://github.com/new_user_name/new_repo.git/': The requested URL returned error: 403
That means I'm still logged in with the old account. What else can I do?
The user.name and user.email settings are not logins, in any way, shape, or form. (The credential.helper setting is useful here, but just unsetting it is probably not right.)
Whenever you make a new commit (by, e.g., running git commit), Git needs to know what user name and email address to put in the new commit. Git gets these by reading user.name and user.email at that time. That's all they're for: to set these in new commits.1
When you run git push, you do (usually2) need to authenticate in order to send your new commits to some other Git repository. Git does not do this authentication. Git relies on other programs to do it. Those other programs include:
Web servers, via https URLs: here, Git has to send a user name and password or PAT or some other secret to the web server. Git gets these from:
the URL, if they're in the URL;
a credential helper, which you may configure: Windows Git comes with a Windows-specific credential helper, macOS Git comes with a macOS-specific credential helper, and so on; or
as a last resort, reading the user name and password from the keyboard.
Generally the right way to do this is with a credential helper. See the gitcredentials documentation and the specific credential helpers available for your particular Git installation. The problem with method #1 is that the password is visible right there in the URL by anyone looking at your computer; the problem with method #3 is obvious.
Unsetting the credential helper gets you the default for your system. This might not be the best thing to do. For Windows systems, see Remove credentials from Git and in particular VonC's answer here.
Secure Shell (SSH): here, Git simply runs the ssh command. Windows systems come with their own ssh command these days, and Git-for-Windows comes with its own ssh command because the older Windows systems either lacked ssh entirely or provided an inadequate version, so on Windows systems, you must make sure that you configure and use the correct ssh (whatever that may be for your installation).
Since you are using an https:// URL, you will need to set up your credential system. If you wish to use ssh:// URLs, set up ssh.
1Note that git rebase works by copying existing commits to new and (supposedly / intended-to-be) improved ones, so this too uses the settings: it's making new commits.
2One can set up a completely open, anonymous network where anyone can push anything at any time, but these are way too easy to abuse, so nobody does this in practice.

How Can I Configure GitHub Desktop/Windows to Work with a Proxy?

New to working with git in Windows. I downloaded the GitHub Desktop application and can connect my account, but doing pushes/pulls fails because of an unresolved host. Asking around the workplace I got the following suggestion to type this command into the git shell.
git config --global http.proxy http://username:password#proxy.workplace.com:8080
Does this:
Store my password in plain text?
Send my password in plain text?
Doesn't GitHub for Desktop generate and use SSH keys instead (I got an email notification when I first connected my account)? How can I configure GitHub Desktop to work with this proxy?
To directly add a proxy to Github Desktop without using git shell:
Set up/Sign in to your account in Github Desktop(This won't be a problem, proxy only doesn't allow you to Add, create or clone repo)
Close Github Desktop for the time being(to set up proxy).
Go to C:\Users\#yourusername.
There you will find a file named .gitconfig
Open it with any text editor(I have used sublime text 3) and add
[http]
proxy = http://username:password#your.proxy.address:8080
and save.
Now you can add, create and clone repos in Github Desktop.
Note(for TFS users): TFS will return 502 bad gateway error when you use the above proxy configuration. Use hash # to comment out the proxy config in .gitconfig to switch between Git and TFS.
So actually the solution was to type this command into the git shell.
git config --global http.proxy http://<proxy-ip>:<proxy-port>
Try and upgrade to GitHub Desktop 2.4 (March 2020)
Working behind a proxy
With GitHub Desktop 2.4, we automatically handle setup without needing you to configure anything manually—worry no more!
It might work with this:
git config --global http.proxy proxy_address:proxy_port
git config --global https.proxy proxy_address:proxy_port
If username and password are not that much important then use:
git config --global http.proxy username:password#proxy_address:proxy_port
git config --global https.proxy username:password#proxy_address:proxy_port

How do I update the password for Git?

I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (thanks Adobe!).
Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (Authentication failed for 'https://______.git'), but I'm forgetting how to update the cached password on my iMac. Somehow I've been unable to find it on Google or Stack Overflow, though it seems to me it should be rather straightforward...
To fix this on macOS, you can use
git config --global credential.helper osxkeychain
A username and password prompt will appear with your next Git action (pull, clone, push, etc.).
For Windows, it's the same command with a different argument:
git config --global credential.helper wincred
None of the other answers worked for me on MacOS Sierra 10.12.4
Here is what I had to do:
git config --global --unset user.password
Then run your git command (ex. git push) and reenter your username and password.
In Windows 10 with Git
Remove/update related Credentials stored in Windows Credentials in >>Control Panel\All Control Panel Items\Credential Manager
Or you can just use the search bar and search for "CredentialManager" or "Windows Credentials", which should return an entry to open that Control Panel pane (at least for English users).
The only way I could modify my git password was to go to Credential Manager in Windows (Windows Key + type 'credential') and edit the git entry under Windows Credentials 🡒 Generic Credentials.
Note: Not listed alphabetically
I had the same problem, and the accepted answer didn't help me because the password wasn't stored in the keychain. I typed:
git pull https://myuser#bitbucket.org/mypath/myrepo.git
Then console asked me for my new password.
In windows 10 as mentioned above by #Imran Javed you can find Generic Credentials at :
Control Panel\All Control Panel Items\Credential Manager --> Windows Credentials
find your git server and than you can update password by clicking edit button.
For Mac
If you have multiple remote repositories (Github, Bitbucket, Job, etc.)
1) run in the project directory
git config --unset user.password
2) run remote git command (ie. git push or git pull)
Git will prompt you to reenter your user.name and user.password for this repository
Or you can do it globally if you have only one remote repository
git config --global --unset user.password
If you are MAC user then you can open KeyChain Access Application from finder and then look for your account listed there. Just click on it and update your password.
Now give a try and things will fall in place.
link for reference: Updating your credentials via Keychain Access
None of the other answers worked for me on MacOS Big Sur 11.3.1
I had Two-Factor Authentication enabled on Github, this makes is so you will fail when entering your username and password even when they are correct.
Here is what I had to do:
git config --global --unset user.password
Then run your git command (ex. git push) and enter your username.
For the password you need to generate a Personal Access Token.
Go to https://github.com/settings/profile select the Developer Settings on the right. Select Personal Access Token Generate new token. Copy the generated token and use it as the password in terminal.
running git config --global --unset user.password followed by any git command would prompt you to enter username and password.
git config --global --unset user.password
git push (will prompt you for the password)
git status (will not prompt for password again)
In my Windows machine, I tried the solution of #nzrytmn i.e.,
Control Panel>Search Credentials>Select "ManageCredentials">modified new credentials under git option category corresponding to my username.
And then,
Deleted current password:
git config --global --unset user.password
Added new password:
git config --global --add user.password "new_password"
And It worked for me.
If your credentials are stored in the credential helper, the portable way to remove a password persisted for a specific host is to call git credential reject:
$ git credential reject
protocol=https
host=bitbucket.org
⏎
or
$ git credential reject
url=https://bitbucket.org
⏎
After that, to enter your new password, type git fetch.
Given the new token authentification requirement from August 13 2021, this may be what you are looking for:
Generate a new access token
Update the token used to access your repo
git remote remove origin
git remote add origin https://[TOKEN]#github.com/[USER]/[REPO]
git push
There is such a confusion on this question, as there is way too much complexity in this question. First MacOS vs. Win10. Then the different auth mechanisms.
I will start a consolidated answer here and probably need some help, if I do not get help, I will keep working on the answer until it is complete, but that will take time.
Windows 10: |
|-- Run this command. You will be prompted on next push/pull to enter username and password:
| git config --global credential.helper wincred (Thanks to #Andrew Pye)
`
MacOS:
|
|-- 1. Using git config to store username and password:
| git config --global --add user.password
|
|---- 1.1 first time entry
| git config --global --add user.password <new_pass>
|
|---- 1.2 password update
| git config --global --unset user.password
| git config --global --add user.password <new_pass>
|
|-- 2. Using keychain:
| git config --global credential.helper osxkeychain
|
|---- 2.1 first time entry
| Terminal will ask you for the username and password. Just enter it, it will be
| stored in keychain from then on.
|
|---- 2.2 password update
| Open keychain, delete the entry for the repository you are trying to use.
| (git remote -v will show you)
| On next use of git push or something that needs permissions, git will ask for
| the credentials, as it can not find them in the keychain anymore.
`
I was pushing into the repository for the first time. So there was no HEAD defined.
The easiest way would be to:
git push -u origin master
It will then prompt for the password, and once you enter that it will be saved automatically, and you will be able to push.
If you are using github and have enabled 2 factor authentication, you need to enter a Personal access token instead of your password
First reset your password:
git config --global --unset user.password
Then, log to your github account, on the right hand corner, click on Settings, then Developer Settings. Generate a Personal access token. Copy it.
git push
The terminal will prompt you for your username: enter your email address.
At the password prompt, enter the personal access token instead.
do these steps in Terminal:
Delete current password saved in your Mac
git config --global --unset user.password
Add your new password by using this command, replace with your new password:
git config --global --add user.password <new_pass>
you can change password through command line in 2 places, following would edit credentials to connect the repo
git config --edit
The credentials also can be changed at global using global parameter like below
git config --global --add user.password "XXXX"
or set the credentials helper with
git config --global credential.helper wincred
but if you have repo level credentials set the use the first command
git config --edit
For MacOS based on the new rule to use password tokens from August 13 2021.
I tried all other terminal based answers but none worked.
Simply head to Keychain Access
Search for github
Right click on all github related items, including vs-code,
Delete all items
my password was good in github desktop preferences but wrong in the .git/config file
for me the only working solution was to manually edit the file:
.git/config
that contains this line:
url = https://user:password#github.com/user/repo.git
change password to the GOOD password because it was an older one for me
I was able to change my git password by going to Credential Manager in Windows and deleting all the git entries under Windows Credentials 🡒 Generic Credentials.
When doing a git pull or git push, windows will ask for the new user/password itself.
I would try to delete my account in Keychain Access and then run git clone again. Git will ask me for a new password.
on mac BigSur 11.2.3
I updated the credentials in the key chain then I ran the command below.
git credential-osxkeychain erase
host=github.com
protocol=https
I had to do this because no other solution in this thread worked for me after changing to token auth for github. github kept stating repository not found.
If this does not work try to combine this with the other commands for mac in this thread.
Just clone one of your existing repos, this will prompt you for new credentials:
e.g.
git clone https://myuser#bitbucket.org/mypath/myrepo.git
(where https://myuser#bitbucket.org/mypath/myrepo.git is an address of one of your existing repos)
Tried everything but nothing worked. Then the following did work.
Before any of the above steps, lock and unlock the keychain again coz sometimes it sorta gets stuck.
Install the GitHub Desktop — it helps.
For those who are looking for how to reset access to the repository. By the example of GitHub. You can change your GitHub profile password and revoke all "Personal access tokens" in "Settings -> Developer settings" of your profile. Also you can optionally wipe all your SSH/PGP keys and OAuth/GitHub apps to be sure that access to the repository is completely blocked. Thus, all the credential managers, on any system will fail at authorisation and prompt you to enter the new credentials.
Following steps can resolve the issue .....
Go to the folder ~/Library/Application Support/SourceTree
Delete the file {Username}#STAuth-bitbucket.org
Restart Sourcetree
Try to fetch, password filed appear, give your new password
Also can run git fetch command in terminal and need to type password
Done
None of the command line options from within terminal worked for me. Ultimately, I just opened up keychain manually, searched for 'git' under 'All Items', found an entry there and deleted it. That did it! Next time I tried a git pull from the terminal and it prompted me for new creds.
For MAC users, using git GUI (Works for Sourcetree, may work for others as well). Would like to add a small remark to Derek's answer. The original suggestion:
$ git config --global --unset user.password
should be followed by a push/pull/fetch BUT it might not work when done from the GUI. The %100 working case would be to do the very first consecutive prompt-triggering git command from console. Here is an example:
Locate to your git repository root directory
Type in $ git config --unset user.password
Proceed with a git commend of your choice in terminal e.g.: $ git push
Then it will ask you to provide the new passoword.
On macOS, e.g. after OSX v.11.6, should go to KeyChain and search "git". And delete the relevant keys. It will work.

git mac application

So, I Just started to use GitHub, and I downloaded the application. And If I do commit something of to my github it uses my username of my computer, how do I change it to use the username of my github account?
So Question: How do you get the GitHub application (mac) to use your own github account username instead of your computers account username
In the github application, click Github -> Preferences, and verify what your name is set to.
You can also see what name your git repo will use from the command line.
cd /your/git/repo
git config user.name
If you want to change the user name for just that repo...
cd /your/git/repo
git config user.name "joe smoe"
If you want to change your user name for every repo
git config --global user.name "joe smoe"
https://help.github.com/articles/setting-your-username-in-git
Lastly, double check 'how' you are pushing up your commits. You may be using https which behaves differently than ssh. I can't say for sure how http behaves because I always use ssh.

Resources