2

I have two accounts on Github (let's say they are a1 and a2). With my a2 profile, I created an origanization and a new repository for it (from Github's website). My computer has the following ~/.gitconfig file:

[core]
    editor = pico
[user]
    name = a1
    email = mail_a1@example.com

(because most of the time I use my a1 account).

Now I wanted to work on the repository of the organisation I created with a2 so I did the following:

cd project_folder
touch README.md
git init
git config --local user.name a2
git config --local user.email "mail_a2@example.com"
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/myorganisation/myrepo.git

Then, just to be sure my commit was done by a2, I did git log, obtaining:

commit e8dd182a12023a490cb2f099ea8b3a94afe6b81b
Author: a2 <mail_a2@example.com>
Date:   Wed Dec 14 17:12:10 2016 +0100

    first commit

Great. But when I tried to git push -u origin master, I got a 403 message saying that I was trying to push as a1:

remote: Permission to hivex-unipd/swedesigner.git denied to gigiobello.
fatal: unable to access 'https://github.com/myorganisation/myrepo.git/': The requested URL returned error: 403

Did I forget something? Why does Github thinks I'm a1 even after I'v configured my local repository with the a2 account?

Giorgio
  • 2,137
  • 3
  • 20
  • 40
  • did it ask you to authenticate when you tried to do `push`? Is it possible that you used [credential helper to cache your github password](https://help.github.com/articles/caching-your-github-password-in-git/)? – Igor Milla Dec 14 '16 at 16:47
  • It didn't ask me to authenticate but when I type `git config --list` I can see that `credential.helper` is set to `osxkeychain` (I'm on a Mac). – Giorgio Dec 14 '16 at 17:17
  • have you tried going to keychain and removing there all github credentials(considering you know your credentials and can login without keychain), rebooting machine, and checking if you will be asked for credentials next time you try to do `push`? – Igor Milla Dec 14 '16 at 17:22
  • Your link was helpful, thank you! I had to update the key in Keychain Access (actually I deleted it), so now Git asks me for username and password and the `push` works as expected. – Giorgio Dec 14 '16 at 17:23
  • cool, i will post it all as answer, so you can accept and close this question – Igor Milla Dec 14 '16 at 17:33

1 Answers1

1

From github documentation:

If you're cloning GitHub repositories using HTTPS, you can use a credential helper to tell Git to remember your GitHub username and password every time it talks to GitHub.

If this is your case, On MacOS, your credentials will be stored in your keychain. You can confirm this by running the following command:

git config --list

See if you have credential.helper set to osxkeychain.

The easiest way to force Git to ask for your github credentials is to go to your keychain and remove there all Github entries.

Giorgio
  • 2,137
  • 3
  • 20
  • 40
Igor Milla
  • 2,767
  • 4
  • 36
  • 44