9

After recently taking a programming course online which required us to upload our homework assignments into Github, ever since then whenever I type git push -u origin master I get:

remote: Permission to my-github-username/mygithubrepo.git denied to rheros.
fatal: unable to access 'https://github.com/my-github-username/mygithubrepo.git/': The requested URL returned error: 403

rheros is the name of the repository that I used to push my homework assignments to. Obviously, now I'm not using rheros anymore, yet the command line thinks I'm still trying to push to it. I tried checking whether I have a faulty SSH key, but everything looks fine.

How can I make my command line effectively forget about the existence of a completely irrelevant directory that I pushed to before?

EDIT git remote --verbose gives:

origin  https://github.com/my-github-username/mygithubrepo.git (fetch)
origin  https://github.com/my-github-username/mygithubrepo.git (push)

So far, none of the suggestions below have helped me: it seems that the rheros repo is running somewhere in the background of my command line, and I can't figure out how to eliminate it.

suka_snake
  • 91
  • 1
  • 1
  • 5
  • could you add (and comment on) the results of `git remote --verbose` – user3276552 Aug 12 '15 at 23:35
  • @user3276552 Done, see edit. – suka_snake Aug 13 '15 at 03:50
  • @user3276552 It seems that rheros is trying to access my .git.... how do I remove this activity? – suka_snake Aug 13 '15 at 03:57
  • Instead of it git remote add origin https://github.com/my-github-username/mygithubrepo.git, should be git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git to change the origin – Max Pinto Aug 13 '15 at 03:57
  • @MaxPinto Yes, but I am not `rheros`. I want to reset myself so that my computer doesn't think that I, as `rheros`, am trying to gain access to `https://github.com/my-github-username/mygithubrepo.git` – suka_snake Aug 13 '15 at 04:01
  • ok try to to this: git config --global --list, check this guide: http://askubuntu.com/questions/206449/git-config-global-file-remove-settings – Max Pinto Aug 13 '15 at 04:04
  • @MaxPinto This gives `fatal: unable to read config file '/Users/my-username/.gitconfig': No such file or directory` – suka_snake Aug 13 '15 at 04:07
  • at least publicly, there is no user **my-github-username** and that hypothetical user has no repository called **mygithubrepo**. Is this about changing the username associated with you github login? – user3276552 Aug 13 '15 at 04:09
  • looks like you dont have installed git – Max Pinto Aug 13 '15 at 04:09
  • another situation could be user permissions, if you are on some linux distro try to run with sudo/su before. If is another with administrator permissions. if is that, and you are in linux, you must give permissions to your user, example: sudo chown username:username /home/username Regards – Max Pinto Aug 13 '15 at 04:12
  • @user3276552 I want to get rid of `rheros` so that it doesn't keep thinking that I'm trying to access my .git with it. This may well be about changing the username associated with github login. I have absolutely no idea. – suka_snake Aug 13 '15 at 04:13
  • @user3276552 Actually, now that you say it, it may very well be that my command line thinks that I am trying to access my own .git as the username rheros. Could it really be possible that I am logged in as rheros? – suka_snake Aug 13 '15 at 04:15
  • yes, github thinks your're `rheros` – user3276552 Aug 13 '15 at 04:15
  • When I go to my github page in my internet browser, I am logged in correctly. But maybe I also need to tell the command line that I am who I am. How would I accomplish this? – suka_snake Aug 13 '15 at 04:18
  • what's your github username and the repo you're trying to push to? do you have a second account registered on github? – user3276552 Aug 13 '15 at 04:20
  • Yes, okay this might be a problem that I have multiple Github accounts – suka_snake Aug 13 '15 at 04:22
  • I just did `git config --global user.name`... my username is correct. So now I don't know what the problem could be again... – suka_snake Aug 13 '15 at 04:25
  • do you have _any_ ssh keys set up with _any_ accounts on github? – user3276552 Aug 13 '15 at 04:30
  • No, what if I just reinstall git on my machine? How can I delete git and then reinstall it? – suka_snake Aug 13 '15 at 04:33
  • that shouldn't make a difference. This sounds like a problem with authentication, not git. – user3276552 Aug 13 '15 at 04:36
  • just to make things _very_ clear: `https://github.com/my-github-username/mygithubrepo.git` does not (publicly) exist. – user3276552 Aug 13 '15 at 04:38
  • Here's what I'm looking at now: http://stackoverflow.com/questions/21615431/git-pushes-with-wrong-user-from-terminal – suka_snake Aug 13 '15 at 04:38
  • that sounds more like it. You need a way to make it ask for your credentials again so it doesn't assume you're rheros this time, and lets you specify who you want to be. The keychain answer over there sounds encouraging. – user3276552 Aug 13 '15 at 04:43
  • for what it's worth, I'd suggest deleting the question. It's turned into an awful lot of noise, and has diverged pretty far from the original _git is pushing to the wrong repo_. Someone else could argue a reason to keep it but that's just my two cents. – user3276552 Aug 13 '15 at 04:48
  • Question: I have two github accounts (one called rheros and one called sukasnake). I want to push to sukasnake.... yet the command line thinks that I am rheros.. any suggestions for how to log out of rheros now? I don't have any ssh keys in either account... – suka_snake Aug 13 '15 at 04:51
  • are you on linux, mac, or windows? – user3276552 Aug 13 '15 at 04:54
  • try [this](http://stackoverflow.com/questions/13198143/how-do-i-disable-gits-credential-helper-for-a-single-repository/13203623) or [this](http://stackoverflow.com/questions/18947897/how-do-i-force-git-to-prompt-for-credentials) – user3276552 Aug 13 '15 at 04:56
  • @user3276552 I finally got it to work, here's what I did: I deleted my rheros Github account (it was a throwaway account I used for the class). Then I proceed to use `git push -u origin master`, which asked me for my new Github credentials. Voila. Thank you for your extended help in allowing me to figure out what my issue really was: i.e., one Github account interfering with another. – suka_snake Aug 13 '15 at 05:11

6 Answers6

8

First check what the current git repository is, if any using:

git remote -v

Then, confirm your new repository exists by checking the github website and copying the right repository url

Overwrite the repository url by running:

git remote add origin https://github.com/my-github-username/mygithubrepo.git

Try git push again:

git push origin master
2
git remote remove origin https://github.com/my-github-username/mygithubrepo.git

After this, you can add the repository you want to push to normally

Gshock
  • 21
  • 2
2

if your want to change your current origin path, try:

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
1

See the solution discussed here: https://superuser.com/questions/1064197/how-to-switch-git-user-at-terminal

My issue was that git credentials were stored in Keychain. Delete them from keychain and you may have some luck.

0

Do

git remote add origin https://github.com/my-github-username/mygithubrepo.git

Then try push again

meda
  • 45,103
  • 14
  • 92
  • 122
0

This happens because github is trying to look for wrong repository (Most Probably). Solution is simple. Follow these steps.

  1. Check if origin is pointing to right url for your repo using
    git remote -v
  1. If not remove all the origin using
    git remote rm origin
  1. Go to github-desktop and try to push it to the repo. if it says repo name already exist, delete the repo from github.com
  2. Try to push it again from github-desktop
  3. check for your origin url using. It should be now pointing to right url.
    git remote -v