I am trying to push a project to a remote repository from the command line.
From inside my local directory, I hit:
$ git pushand obtain the following error:
remote: Permission to username1/repo.git denied to username2.
fatal: unable to access '':
The requested URL returned error: 403
Where username1 is my github account username hosting the repository I want to push to and username2 is an old account I used to use on this machine.
I am using OS X Yosemite (v10.10.5) on a Macbook Air. And I would prefer to use https instead of ssh.
How do I update to username1 so I can successfully push to my remote?
Edit: To be clear, I am not talking about simply editing the config user object, e.g.,
$ git config --global user.name "Billy Everyteen"
$ git config --global user.email ""They have nothing to do with authentication. My question deals with user authentication necessary to write to my remote repository.
66 Answers
In addition to changing username and email from terminal using git config:
$ git config --global user.name "Bob"
$ git config --global user.email ""you'll need to remove authorization info from Keychain. This is something I've also struggled with until I found that I also had certificate in my Keychain.
Open up Keychain access, click on All Items and search for git. You will get some items like this:
Delete them. Now try to push the repo and git will ask you to write password for the user and you will be good to go.
6For cli users, just use this : git config credential.username 'Billy Everytee'
List your git config.
git config --listChange username and email global
git config --global user.name "Nanhe Kumar"
git config --global user.email ""Change username and email for current repo
git config user.name "Nanhe Kumar"
git config user.email ""Change your repo url if you are using bit bucket.
nano .git/configThis file will be something like this.
[core] repositoryformatversion = 0 fileMode = false bare = false logallrefupdates = true ignorecase = true precomposeunicode = true
[remote "origin"] url = fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"] remote = origin merge = refs/heads/master` [user] name = Nanhe Kumar email = 2 For Windows User:
Follow Instructions:
Control Panel >> User Account >> Credential Manager >> Windows Credential >> Generic Credential
remove git credential.
next time when you'll push repo it'll ask you for credential.
Answer reference for detailed explanation
Other plausible option, if you wanted to use the "new user" on only one project, you can do it by configuring it just for the project's directory in which you are working. e.g:
git config --local user.name "Mike" git config --local user.email ""note that I'm using --local instead of --global.
2If you're on windows you can simply use GitManager (GitAccountManager on npm): . There you can do it all with only one command.
1