I am getting an error trying to do a git push to a repository in my github codespace

268 views Asked by At

I have created a github codespace that I attached (I think) to a particular github repository that I own. However, when I attempt to do a git push to the remote repo, I'm getting the following error:

remote: Permission to <username>/<reponame>.git denied to <username>.
fatal: unable to access 'https://github.com/<username>/>reponame>/': The requested URL returned error: 403

How can I check that the codespace is attached to the repo in question? Any other debugging hints?

Thanks

2

There are 2 answers

4
Vivek Tikar On

I see that you are trying to link codespace to some other repository that you own. But by default, Codespace limits access to only repository from which it was created.

So you can either create a brand new codespace for your other repository.

OR

If you want to access other repository from your existing codespace then you will have to update your devcontainer.json to set additional permissions to access this other repository.

Please refer to these official docs -

  1. https://docs.github.com/en/codespaces/managing-your-codespaces/managing-repository-access-for-your-codespaces
  2. To set additional permissions - https://docs.github.com/en/codespaces/managing-your-codespaces/managing-repository-access-for-your-codespaces#setting-additional-repository-permissions

I hope this answers your question.

0
weakish On

How can I check that the codespace is attached to the repo in question

You can see all your GitHub codespaces via https://github.com/codespaces

user1/repo1 <-- this is the username/repo the codespaces attached
codespace1

user2/repo2
codespace2

For example, assuming you are user2:

  • If codespace1 is attached to user1/repo1 but and user1 does not grant you write permission to user1/repo1, then git push under codespace1 will result in permission denied.
  • Assuming you do not have write access to user1/repo1, the best practice is to first fork user1/repo1 to user2/repo1, then create a codespace under user2/repo1. Thus, you can push to your fork (user2/repo1) and send pull request to upstream (user1/repo1). If you first create a codespace under user1/repo1, then fork user1/repo1 to user2/repo1, you can neither push to the upstream (user1/repo1) nor push to your fork (user2/repo1) under that codespace.