Reputation: 2666
This question seems obvious, but I can't seem to find a direct answer in my searching of stackoverflow and other corners of the internet.
I have a project I work on using R studio on a local machine. The project started by pulling from a repo on Github. I can't push to this repo, as its not mine and I don't have permission. No big deal, I'd like to create a new repository on github to save all my changes to the original repo and the current state of the project. I can't just enter:
git remote add origin https://github.com/user/new_repo.git
Because there is already a remote origin. I receive this error:
fatal: remote origin already exists.
Right. This is clear. The origin is the original github repository that I pulled this from, and also the one I am not allowed to update because its not my code. Straightforward. I want to change the origin of the repository to: https://github.com/user/new_repo.git
(the new repo I just setup on github), but save all of the work history of how I have modified the project.
Apologies if this is a duplicate and I don't understand the other responses to similar questions.
Upvotes: 0
Views: 519
Reputation: 2666
I solved this problem using advice from @manishrw, and several other posts. I needed to do several things:
First,
I needed to change the origin remote url in the .git/config
file. This could be accomplished as detailed by @manishrw, and the actual URL filepath needed to be ssh://[email protected]/user/new_repo.git
. So, from the home directory you would enter:
git remote set-url origin ssh://[email protected]/user/new_repo.git
So far so good. However, I still had problems, as I was working from a remote computer which had never been authenticated. I would get the error:
Permission denied (publickey). fatal: The remote end hung up unexpectedly
Second, To solve this I had to setup my username and email for github on the remote machine, and then generate an SSH key. I followed instructions here, which I summarize below:
Set username and email at the shell within R studio. These are your github.com username and email.
git config --global user.name "your_username" git config --global user.email "[email protected]"
In RStudio, go to menu Tools / Global options / Git SVN
Click "Create RSA key..." and follow instructions. You can set a password here, but its not necessary.
Click "view public key" and copy the key.
Copy the key to your Github account setting (Edit profile / SSH keys / Add SSH key).
To check that ssh-authentication works, try to run
ssh -T [email protected]
and you should get something like
Hi your_username! You’ve successfully authenticated, but GitHub does not provide shell access.
Everything should now work awesome.
Upvotes: 0
Reputation: 429
This should do it.
git remote set-url origin newurl
EDIT:
When you clone with the git read-only address (mostly when you don't log in), then you don't get read+write access.
Repository needs to change the way it pushes using ssh. Follow this answer to change your repo config on your PC to ssh way.
Upvotes: 1