10

If remote (using ssh) does not contain the git repository, is it still possible to copy the local repository to remote and setup the remote tracking without manually copying the files using scp and doing then followed by a git clone?

Ryan
  • 10,041
  • 27
  • 91
  • 156

2 Answers2

11

You do need to setup the repository on the remote, but you shouldn't copy the files manually. At the very least, you don't get the history with it.

First, ssh to your remote and do this:

mkdir your_repo.git
cd your_repo.git
git init --bare

The .git in directory name is completely optional. The --bare option makes the repository without index and is therefore pushable.

You then go back to your local repository and add the remote:

git remote add remote_name user@remote.address:path/to/your_repo.git

You are all set. All you need to do now is:

git push remote_name
Shahbaz
  • 46,337
  • 19
  • 116
  • 182
  • Thanks, what if I want my remote is not a bare repo, also possible? Thanks – Ryan Jul 08 '12 at 11:30
  • 1
    Generally, that's not a good idea. I'm not sure if it is at all possible, but even so, pushing to non-bare repositories means that on that repo, all your stuff need to be merged without causing conflict, but there is no guarantee for that. See also [here](http://stackoverflow.com/questions/1764380/push-to-non-bare-repository), [here](http://gitready.com/advanced/2009/02/01/push-to-only-bare-repositories.html) and [here](http://sitaramc.github.com/concepts/bare.html) – Shahbaz Jul 08 '12 at 11:52
2

is it still possible to copy the local repository to remote and setup the remote tracking without manually copying the files using scp and doing then followed by a git clone?

If you have a ssh access, you could copy the repo (yes, with a scp), but copying only one file: a git bundle.

From there, you can clone that bundle as a bare repo (that one file acts as a repo you can clone) on your remote server and use it as a remote repo (you can push to a remote bare repo).

The advantage over pushing directly to an empty bare repository is the initial copy here is one file. For a large repository, that can make the initialization easier/less dependent on the network.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It seems to be a very nice answer. But, I had to go through the question twice to understand this. May be the reason for less acceptance. – KnockingHeads Jun 14 '21 at 06:11
  • @Ashish 9 years later, I agree. I have copied the relevant part of the question in my answer, to at least have it closer. – VonC Jun 14 '21 at 07:02