Reputation: 21
I cloned an existing repo from Git (Bitbucket) and copied that file to a new location. Now I wanted to push that to an empty repository to Bitbucket as a new project with changes that are related to that project. This happened:
git remote add origin
fatal: remote origin already exists
After that I checked the git version (with $ git remote -v) and it indicates to the original cloned git repo from the last project. Is there a way to remove the git history so that I can do git init and push the project to a new repo? If I use rm -rf .git will that harm the original cloned git repo? Or can I then initialize the new project and push that to the new empty repo?
Upvotes: 1
Views: 260
Reputation: 515
You can simple add a new remote (git remote add new_origin destination
), or rename the actual (git remote rename origin old_origin
), or delete the actual (git remote rm actual_destination
).
Upvotes: 0
Reputation: 7270
Inside .git you store everthing related to your local clone of a git repository. In your case it should be no problem to delete it and rerun git init . after. Once you have done this you have to commit your complete folder …. so your commands could look like (pseudo)
$ cd new_project
$ rm -rf .git
$ git init .
$ git add *
$ git commit -m "Initial commit of my fork"
$ git remote add …
$ git push
However, this would purge the complete history of the base of your fork. I would consider this bad style and might conflicts with copyright depending on license original project is used. why not conside a full fork and do something like:
$ cd original_repo
$ git remote add -f myfork <bitbucketurl>
$ git push myfork
After that has be done you can either remove the original origin from your clone or just reclone from bitbucket. This would keep original history.
Upvotes: 1
Reputation: 2167
The reason why you are getting this
fatal: remote origin already exists
is because origin
is a local version of a remote repository. Think of it as a folder with a name origin
.
Just change the name when you add a remote
git remote add <name> <url>
You can use whatever name you like, as long as it doesn't violate conditions applied by the file system
Alternatively, you can remove the remote
origin.
git remote rm origin
Note: This will remove local copy of a remote repository named origin
from your file system!
Upvotes: 2