Cannot push to my organization repositories

2k Views Asked by At

I've just created a Github organization with two repositories, but It seems that I can't push/pull/fetch to either of them. It displays this error message when I run git push -u origin master:

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Reading a bit about this problem, I've tried this so far:

  1. Created a new ssh key.
  2. Set name and email in git config:
git config --local user.email "[email protected]"
git config --local user.email "myusername"
  1. Created a new ssh-key and added it like this:
ssh-add ~/.ssh/my_ssh_key
  1. Deactivate third-party applications restrictions in the organization settings.

None of this seems to work. The project and the repositories are brand new, and I am just trying to push my initial changes to them.

git init
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin [email protected]:<organization_name>/repo_name.git
git push -u origin master # here it fails

Any idea about why is not working?

Thanks!

UPDATE: since I have multiple github accounts, running ssh -T [email protected] it displays that I am authenticated other account.

# ssh -T [email protected]
Hi MY_WRONG_ACCOUNT! You've successfully authenticated, but GitHub does not provide shell access.

So I think I need to change that account. (I thought it will change once I run ssh-add ~/.ssh/my_write_acc_key.

2

There are 2 best solutions below

0
On

I stumbled on this today and ended up using an organization fine-grained token in IntelliJ. So for anyone also having trouble with this:

1. Authorize tokens in your organization

On GitHub, go to your organization settings. On the left panel, click the "Personal access tokens" section. You will be taken through several steps where you can configure personal access token creation for your organization. Choose "Allow" for the first step, you can just leave the default value for the rest.

2. Create fine-grained token

Now go to your GitHub account settings. At the bottom of the left panel, click on "Developer settings". Then, under "Personal access token", choose "Fine-grained tokens". Then click on "Generate new token".
Now, on the token creation page, under "Resource owner" you have to select your organization. Then choose "Only select repositories" and select the repository you want to have access to. You can now click on "Repository permissions" and add Contents Read and write access level. Validate your token creation by clicking "Generate token" at the bottom of the page. You will have to copy the token that will be presented to you then.

3. Add token to IntelliJ

In your JetBrains IDE, open your repository project, go to the IDE preferences and search "GitHub". You will find the list of GitHub accounts configured for this project. If your account is already listed, delete it. Then click the "+" button to add a new account and choose "Log In with Token". You then have to paste the token you obtained at the previous step.

Aaaaaaand that's it, you're good to go.

0
On

I would create a second key (without passphrase, for testing), and register its public key to the new account.

ssh-keygen -P "" -t rsa -f ~/.ssh/secondUser

And create a ~/.ssh/config file to reference that second key:

Host gh2
  Hostname github.com
  User git
  IdentityFile ~/.ssh/secondUser

From there, check your key does reference the right user with:

ssh -Tv gh2

And change your remote URL:

cd /path/to/repo
git remote set-url origin gh2:<organization_name>/repo_name.git