Reputation: 7505
I currently have a project with a git repository. I would like to create a shared repository at another location. I had thought the approach I should take would be to first create a bare git repository and then clone my existing repository to it, but this did not work:
me@computer> git init --bare shared.git #Create shared repository in new location
me@computer> git clone .git /path/to/shared/repository/shared.git #From dir with existing repository, try to create clone in shared repository
fatal: destination path '/path/to/shared/repository/shared.git' already exists and is not an empty directory.
I decided next to clone the shared git repository, add all the files from my existing project to the directory with the new repository, next add and commit those files to the new repository and then use git push
to place all these files in the shared repository. This, too, did not work. The error I got was:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/path/to/shared/repository/shared.git'
How can I take the files in my existing repository and put them in a shared repository?
Upvotes: 1
Views: 6422
Reputation: 145829
Create a new empty git repository (e.g., say named shared.git
) as you would normally create.
Clone your existing repository into a dir named shared
:
$ git clone url_to_existing.git shared
Then change the remote of your repository to make origin
point to the new create repository (URL_OF_SHARED_GIT
is the URL of the shared.git
repository):
$ cd shared
$ git remote set-url origin URL_OF_SHARED_GIT
Then push master branch:
$ git push -u origin master
You are done!
Note that it will only push the master branch. If you want to push other branches, you have to do it the same for the other branches. To push tags use git push --tags
. Now if you clone shared.git
it will reflect what you pushed.
Upvotes: 1