Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a copy of local git repository on a remote server

Tags:

git

I have cloned a project from a server using git clone and I now want to copy it (all branches) to another server so other people can start using it. I guess I could simply copy the entire repository manually and then issue git config --bool core.bare true and delete everything but the .git folder but I don't think that qualifies as a 'bare' repository and I'm worried it might give me problems.

I was hoping I could create the new remote repository using git init --bare and simply push my local one to it but as I originally cloned my local copy from another server, the origin seems to be blocking me from doing this.

like image 869
Rob Avatar asked Jan 27 '11 18:01

Rob


People also ask

How do I copy a local repository to a remote?

To clone a Git repository, you will first copy the remote URL from your repository hosting service—in this case GitHub. You will then use the Git clone command followed by the remote repo's URL. If you are working with a private repository, you will be prompted for your remote hosting service credentials.

Can I clone a local git repository?

You can use Sourcetree, Git from the command line, or any client you like to clone your Git repository. These instructions show you how to clone your repository using Git from the terminal. From the repository, select the Clone button. Copy the clone command (either the SSH format or the HTTPS).

What commands would create a copy of a local repository on your system?

The `git clone` command can create a new local repository by copying an existing local repository.


2 Answers

  1. Create a fresh bare repository on the server:
    git init --bare newrepo.git
  2. Add it as a remote in your local repo:
    git remote add newrepo git://[email protected]/newrepo.git
  3. git push newrepo master to push a particular branch, or
    git push --all newrepo to push all branches
like image 125
Roman Cheplyaka Avatar answered Oct 03 '22 21:10

Roman Cheplyaka


Another way is (as you wished):

git clone --bare /path/to/repo newrepo.git 
like image 36
gahooa Avatar answered Oct 03 '22 21:10

gahooa