Copy a Git repo; and dumping the origin

Sometimes you might want to copy a git repo and remove all connection to the old git repo. For example, if you are creating a new repo based on a template project.

First of all clone the template repo into your new project folder.

$ git clone https://bitbucket.org/daemonite/abc-vagrant-template.git xyz-vagrant-newproject
Cloning into 'xyz-vagrant-newproject'...
remote: Counting objects: 76, done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 76 (delta 34), reused 0 (delta 0)
Unpacking objects: 100% (76/76), done.
Checking connectivity... done.

Change into the newly cloned directory and set the origin of the repo to a brand new, blank repo you’ve created, and check the status.

$ cd xyz-vagrant-newproject/
$ git remote set-url origin https://bitbucket.org/daemonite/xyz-vagrant-newproject.git
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Next we push all the code into the new repo. The remote tracking branch may not reflect the status properly, but just push into the empty repo and all will be right in the world.

$ git push
Counting objects: 76, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (71/71), done.
Writing objects: 100% (76/76), 17.58 KiB | 0 bytes/s, done.
Total 76 (delta 34), reused 0 (delta 0)
To https://bitbucket.org/daemonite/xyz-vagrant-newproject.git
 * [new branch](#)      master -\> master

On bitbucket, when doing

$ git push
No refs in common and none specified; doing nothing. 
Perhaps you should specify a branch such as 'master'. 
Everything up-to-date

To fix, use instead

$ git push --set-upstream origin master
Counting objects: 76, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (71/71), done.
Writing objects: 100% (76/76), 17.58 KiB | 0 bytes/s, done.
Total 76 (delta 34), reused 0 (delta 0)
To https://bitbucket.org/daemonite/xyz-vagrant-newproject.git
 * [new branch](#)      master -\> master

Fix courtesy of http://stackoverflow.com/questions/6157730/why-cant-i-push-to-this-bare-repository

1 Like