19

I've recently cloned a repo to my local drive, but now I'm trying to push all changes to a complete new repo. However, git keeps telling me that permission is denied, and that's because it's trying to push to the originally-cloned repo.

DETAILS:

I originally cloned from https://github.com/taylonr/intro-to-protractor (i.e. based on a Pluralsight course at https://app.pluralsight.com/library/courses/protractor-introduction/table-of-contents ) .

Now that I've completed the course, I'd like to push my finalized code up to my own git repo (which I just created on github):

https://github.com/robertmazzo/intro-to-protractor

When I use the following git command:

git remote add origin https://github.com/robertmazzo/intro-to-protractor.git

it tells me remote origin already exists , which I guess is fine because I already created it on github.com.

However, when I push my changes up I'm getting an exception.

git push origin master

remote: Permission to taylonr/intro-to-protractor.git denied to robertmazzo. fatal: unable to access 'https://github.com/taylonr/intro-to-protractor.git/': The requested URL returned error: 403

So I'm investigating how I can switch to my new repository, but this is exactly where my issue is. I cannot figure this part out.

user229044
  • 232,980
  • 40
  • 330
  • 338
bob.mazzo
  • 5,183
  • 23
  • 80
  • 149
  • 1
    Possible duplicate of [Change the URI (URL) for a remote Git repository](http://stackoverflow.com/questions/2432764/change-the-uri-url-for-a-remote-git-repository) – Julien Lopez Sep 06 '16 at 14:35

4 Answers4

17

To change your current origin to a new one, use:

git remote set-url origin <url>

Source: https://help.github.com/articles/changing-a-remote-s-url/

spinalfrontier
  • 567
  • 1
  • 10
  • 20
12

Before you can add a new remote named "origin", you need to either delete the old one, or simply rename it if you still need access to it for some reason.

# Pick one
git remote remove origin            # delete it, or ...
git remote rename origin old-origin # ... rename it

# Now you can add the new one
git remote add origin https://github.com/robertmazzo/intro-to-protractor.git
chepner
  • 497,756
  • 71
  • 530
  • 681
7

origin is only an alias to identify your remote repository.

You can create a new remote reference and push

git remote add new_origin https://github.com/robertmazzo/intro-to-protractor.git
git push new_origin master

If you want to remove the previous reference

git remote remove origin
lubilis
  • 3,942
  • 4
  • 31
  • 54
2

Either add a new remote

git remote add <name> <url>

or, if you completely want to remove the old origin, first do

git remote remove origin

and then

git remote add origin <url>

Note that the message remote origin already exists is not fine. It tells you that the operation failed, i.e. it could not set the new remote.

Martin Nyolt
  • 4,463
  • 3
  • 28
  • 36