0

One day, A other dev commit something with his username on my computer. And At this time it become a kind of curse.

I cannot switch user.

I tryed everything:

git config user.name "new name"

git fetch -p

with all available options, no success

restart computer, no success
delete all ssh key, no success
uninstall and reinstall git, no success.

After all this operation, the command git push are saying to me : Permission to myRepos denied to olduser.

The git config user.name with --global/--local/--system option is : me

Did I forget something (clear cache or something else)?

EDIT

I saw other repos of this old user on my computer. (He worked 1 week on my computer). Maybe there are some conflict?

Thomas Dupont
  • 417
  • 6
  • 20
  • Possible duplicate of [Git's famous "ERROR: Permission to .git denied to user"](http://stackoverflow.com/questions/5335197/gits-famous-error-permission-to-git-denied-to-user) – Joe May 06 '17 at 10:14
  • Which platform is this? Windows? OS X? Linux? Also, execute `git config credential.helper` and post the response. – Lasse V. Karlsen May 06 '17 at 18:31
  • Hello, in on mac with osxkeychain – Thomas Dupont May 07 '17 at 09:46
  • Can you suggest for Windows – Mohit Ashliya Jun 11 '23 at 09:42
  • @MohitAshliya For Windows, use [GCM Core](https://github.com/git-ecosystem/git-credential-manager). It comes bundled with [Git for Windows](https://github.com/git-for-windows/git/releases): `git config --global credential.helper manager` – VonC Jun 11 '23 at 09:55

3 Answers3

3

The first thing to know is "what protocol are you using":

cd /patH/to/my/local/repo
git remote -v

If you see an url ofr origin starting with https, no need to concern yourself with ssh keys: they are not used at all for https urls.

in on mac with osxkeychain

That means your Git could have set its credential helper to OSX Keycchain.

If it is the case (check the output of git config credential.helper), erase that entry matching your remote repo url (for instance, github.com)

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

Then try to push again: if a popup is requesting your credentials, enter your GitHub account and its password: that should be enough to cache your credentials.
The subsequent pushes won't ask you for any credentials (but will reuse the ones you just cached), and will be done with your account again.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

All information from previous commits stays the same. Changing your configuration only affects new commits.

arboreal84
  • 2,086
  • 18
  • 21
  • While this is completely true, it is unfortunately completely irrelevant and thus not an answer to the question since the error message in the question is from `git push`, and thus is about the authentication with the remote repository, and not about the repository history. – Lasse V. Karlsen May 06 '17 at 18:33
0

I just had this issue. After checking repository, environment variables, git configuration all had not reference to the old username it turned out to be due to the fact that I had an old remote url starting with "http:" instead of "https:". I am not sure where it is getting the old username from.

Once I changed the remote url to start with "https:" the git push worked again.

Nick
  • 328
  • 2
  • 10