3
  1. I'm part of an organization, and through the UI I can create a private repository inside that organization.

  2. Going on repository -> setting -> Collaboration and team, I can see I'm the admin

  3. I've created my PAT and in fact, I can commit and push other public repositories.

  4. But if I clone this new repository I get "fatal: unable to access"

Is there anything specific to do when creating repos inside an organization?

If I try to create a new PAT and try to create it for specific repos, I can't see this new repo in the list of my repos! So I have to create it for "All repositories".

Other trials:

  • git clone https://<username>:<token>@github.com/orgName/repoName failed
  • git clone https://<username>@github.com/orgName/repoName failed
  • git clone https://github.com/orgName/repoName of course failed as well

BUT, one strange thing: git clone https://<token>@github.com/orgName/repoName asked me for a password

I didn't go on, maybe it's recognized just as a new username so it was asking for a password

torek
  • 448,244
  • 59
  • 642
  • 775
T. Rossi
  • 465
  • 1
  • 6
  • 23

3 Answers3

2

Turns out for whatever reason you have to use ssh and cannot use PAT and https. After registering a key on GitHub everything worked as expected.

Here is the guide: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys

T. Rossi
  • 465
  • 1
  • 6
  • 23
  • Interesting. I don't know why GitHub do it this way - but note that it's entirely up to GitHub; Git itself doesn't take part in the authentication and access restrictions. – torek Nov 22 '22 at 03:22
  • To change the URL of your remote to be ssh, you use the command `git remote set-url --push `, where `` is the name of the remote you want to push to (by default, there's only one, called `origin`). You can find `` on github. So if you have the default setup, the full command would be `git remote set-url --push origin git@github.com/my-username/my-repo.git` . PS: note that the `--push` option isn't related to `git push` - `--push` just tells `set-url` to change the push URL of the remote you ``d (a remote can technically push and pull from different URLs). – Nick Muise Mar 07 '23 at 15:41
  • By now at least, you CAN use PAT and HTTPS with an organisation repo – Tom Wagstaff Apr 24 '23 at 15:46
1

If it is a private repository that is accessed using the classic Personal Access Token(PAT) try resetting the fetch and push url for the remote repo by running: git remote set-url origin https://<classic PAT >@github.com/organization_name/repo_name

In order to do the same while using the newer fine-grained token: git remote set-url origin https://oauth2:<fine-grained PAT >@github.com/organization_name/repo_name

If indeed the Personal access token above is authorized to access that repo you should now be able to do all functions from before such as cloning, pushing and pulling.

angwalt
  • 117
  • 1
  • 2
1

I was facing the same issue but it turned out the problem for me was the local storage of credentials. It is possible to access an organisation repo over HTTPS using a fine-grained personal access token (PAT). Here are a few things to watch out for:

  1. Make sure your organisation is opted-in to fine-grained personal access tokens as per this discussion
  2. Create a new fine-grained PAT with the organisation as the resource owner and the repo(s) of interest included. That key should at least have access to Contents in the repository permissions.
  3. Lodge your credentials locally. I struggled with this, and in the end just deleted ~/.git-credentials and then on git clone I was prompted to enter my username and the new key. There's probably a better way (but looks like others struggle with unset...)
Tom Wagstaff
  • 1,443
  • 2
  • 13
  • 15