bob.mazzo
bob.mazzo

Reputation: 5627

How to switch to a new remote git repository

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.

Upvotes: 36

Views: 45387

Answers (4)

lubilis
lubilis

Reputation: 4160

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

Upvotes: 9

spinalfrontier
spinalfrontier

Reputation: 829

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/

Upvotes: 40

chepner
chepner

Reputation: 531035

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

Upvotes: 21

Martin Nyolt
Martin Nyolt

Reputation: 4650

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.

Upvotes: 4

Related Questions