Git: permission to [organization] denied to [user]

2.8k views Asked by At

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 = [email protected]

(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 "[email protected]"
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 <[email protected]>
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?

1

There are 1 answers

0
Igor Milla On BEST ANSWER

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.