2

My professor wants us to use his github repository for his course. I created the ssh key, I added the private key to ssh-agent and given the public key to the professor. After I created the project folder and run the following steps:

git init
git add *
git commit -m "Initial commit"
git remote add origin git@github.com:prof_username/repo_name.git
git push -u origin master

I get a permission denied (error 403). I tried both ssh and https url. What's the problem?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
retrobitguy
  • 535
  • 1
  • 6
  • 18
  • 1
    Surely you didn't literally use `git@github.com:prof_username/repo_name.git`? – Biffen Mar 19 '15 at 09:19
  • @Biffen I'd hope that was just to hide the actual user/repo name. – Holloway Mar 19 '15 at 09:21
  • @Biffen as Trengot said, i changed the real user/repo name for privacy. – retrobitguy Mar 19 '15 at 09:57
  • @retrobitguy I assumed as much: It was a bit of a shot in the dark. Is there any more output? It's hard to help without more info, other than referring to https://help.github.com. – Biffen Mar 19 '15 at 10:03
  • @Biffen The message when i do the push is: "ERROR: Permission to prof_username/repo_name.git denied to myusername. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.". I can clone the repo, but seems i can't push on it. My professor needs to do something to fix that? – retrobitguy Mar 19 '15 at 10:14
  • @retrobitguy ‘*make sure you have the correct access rights*’ seems key here. – Biffen Mar 19 '15 at 10:20

1 Answers1

0

If you already have a repository, you don't have to initialise it; Just clone it to your local computer:

git clone git@github.com:prof_username/repo_name.git

And you can set your upstream with:

git branch -u origin/my_branch

[Edit] ...and check what key is used:

ssh -vvv git@github.com
Lars Nielsen
  • 150
  • 11
  • You are right, i don't need to initialize the repo. But the problem persist. the message when i do the push is: ERROR: Permission to prof_username/repo_name.git denied to myusername. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – retrobitguy Mar 19 '15 at 10:06
  • @retrobitguy Did you have any problem cloning the repository? Or is it only when you try to push? Maybe take a look at this: http://stackoverflow.com/questions/13509293/git-fatal-could-not-read-from-remote-repository/20714212#20714212 – Lars Nielsen Mar 19 '15 at 10:21
  • @LarsNielsen No problem with the cloning. My problem is only with the push. I will look the link. Thanks – retrobitguy Mar 19 '15 at 10:25
  • @LarsNielsen Thank you! The solution was in this link :) The problem was that git was using another ssh key, so i created a new rule in the `~/.ssh/config` where i specified the correct key to use with that specific repository. – retrobitguy Mar 19 '15 at 11:00