1

I have 2 git repositories set up, and I did a lot of coding in 1. Someone else grabbed the code to make changes to the code, but never pushed them up.

The changes are now so large, I want to push it to an entirely new repository. I have their computer, and I tried to git remote rm origin. Then i tried git remote add origin <url>, but it gives the following error

fatal: remote origin already exists.

Is there a way to push this to a new origin, and have it entirely forget about the first(like, not even remember it's a branch of the first)?

Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
James Korden
  • 724
  • 4
  • 19

2 Answers2

1

I am not clear with your problem, still giving it a try. You might not need to remove origin. Instead add a new one with some other name like original

git remote add original <url>
git push -u original <branch_name>

Edit To view all the remotes use git remote -v. Check the remote list before adding a new remote. It will tell you which remote_name is available and which is not.

Edit2

If you have already added a 'git origin' to your .git configuration. You can change the remote origin URL in your git config with the following line:

git remote set-url origin git@github.com:{user}/{project}.git
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
0

To remove a remote, use git remote remove <name> you can see more details by git help remote

Also, I believe changing the meaning of origin is not a best practice, if you just need to temporarily push to a new remote, just add it with another name, such as: git remote add <name> <url>

When you add a new remote you can see it with git remote or git remote -v to see url details.

Then using git push -u <your-new-remote> would push your repo to <your-new-remote>

EDIT:

My fault, I didn't notice that git remote rm <name> is also usable since it did not appear in git help remote

shengy
  • 9,461
  • 4
  • 37
  • 61
  • @blunderboy Is it a new syntax or something? `git help remote` only gave me `git remote remove ` – shengy Dec 25 '13 at 02:18
  • Checkout this one http://stackoverflow.com/a/1221874/1310070 And also check your git version. May be earlier version of git had `git remove` But I never saw that. – Sachin Jain Dec 25 '13 at 02:21
  • Instead of `Edit` please update your answer. Quick Suggestion: Please try to male your point clear in short words. It looks like people won't prefer reading this. Just a quick thought.. – Sachin Jain Dec 25 '13 at 02:23
  • @blunderboy It's not `git remove` it's `git remote remove` I think maybe you misread it to the `git rm` command? and also https://www.kernel.org/pub/software/scm/git/docs/git-remote.html did not say there is a `git remote rm`, but this can behave as `git remote remove` – shengy Dec 25 '13 at 02:23
  • Please try to use `git remote remove name`. It does not work my friend. http://git-scm.com/book/en/Git-Basics-Working-with-Remotes – Sachin Jain Dec 25 '13 at 02:27
  • May be you should check your git version as well. Latest version of git use `git remote rm` – Sachin Jain Dec 25 '13 at 02:28
  • @blunderboy my git version is `1.8.5.1` both `rm` and `remove` is documented in https://www.kernel.org/pub/software/scm/git/docs/git-remote.html – shengy Dec 25 '13 at 02:31
  • This led me on the right path, ty. The command I needed was actually `git push --set-upstream master` – James Korden Dec 25 '13 at 02:53