Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push is pushing to the wrong repo

Tags:

github

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.

like image 956
suka_snake Avatar asked Aug 12 '15 23:08

suka_snake


People also ask

How do you change the repository you are pushing to?

You will need to 1) fork the project you want to make changes to into your own github account, 2) clone that forked repo to your local, 3) make changes, 4) push to your own repo.

Why is git push origin main not working?

If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.

How do I reset a push on GitHub?

If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit. To fix the detached head do git checkout <current branch> .

Why is GitHub rejecting my push?

Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused. If another person has pushed to the same branch as you, Git won't be able to push your changes: $ git push origin main > To https://github.com/USERNAME/REPOSITORY.git > !


2 Answers

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
like image 182
Babatunde Hassan Avatar answered Oct 07 '22 08:10

Babatunde Hassan


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

like image 28
Gshock Avatar answered Oct 07 '22 10:10

Gshock