4

I have my project on my local machine, with git versioning.

I buy server, I install git, now I want clone my local project to my server (exactly the opposite of what we do generaly).

I don't have gitlab or github here.

How can I do that? How download my local git project to my server?

EDIT: solution

2 steps:

1- apply good answer of this topic (to create a "git server" with only git files)

2- and connect to server and apply :

cd /my/true/directory/for/my/app
git clone file:///opt/git/project.git

In fact, we have to create a "server" git where to push (local to server), and where to pull (true directory on server from server)

Matrix
  • 3,458
  • 6
  • 40
  • 76
  • If your server can access your local machine, http://stackoverflow.com/a/377293/240443 . If it can't, same answer, but with `ssh -R 9418:localhost:9418 server` . – Amadan Jan 05 '15 at 10:08
  • Just to be sure: Do you really want to *clone* it on your server, or do you actually intend to *push* it to your server? – Rahel Lüthy Jan 05 '15 at 11:09
  • @Amadan my problem is : I have many local machine with many internal IP with uniq public IP (internet). So I can't access to my local machine from my server... – Matrix Jan 05 '15 at 11:23
  • @netzwerg I want push, but for this moment, project does't existe on my server, so I have to clone it for the first time. – Matrix Jan 05 '15 at 11:24
  • I take back my answer below. This is probably the simplest way. http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/ – Holloway Jan 05 '15 at 11:27
  • That is why I suggested remote tunneling. Use the command above to access the server; then at the server `localhost:9418` is actually your local machine's `:9418`. – Amadan Jan 05 '15 at 22:49

3 Answers3

7

The steps required are:

  1. On the server: Set up a bare repo

    cd /opt/git
    mkdir project.git
    cd project.git
    git init --bare
    
  2. On your local machine: Add the repo as a remote

    cd yourproject
    git remote add origin git@gitserver:/opt/git/project.git
    
  3. On your local machine: Push to the server

    git push origin master

All details are documented in Chapter 4.4 of the 'Pro Git' book.

Rahel Lüthy
  • 6,837
  • 3
  • 36
  • 51
  • this solution don't clone my project, there is only git files in my directory on my server. no files about the projct himself... – Matrix Jan 05 '15 at 13:54
  • @Matrix That's because it's a bare repository. A bare repository doesn't have a working tree. – musiKk Jan 05 '15 at 14:01
  • I want have my project files. How can I do that? – Matrix Jan 05 '15 at 14:02
  • That's exactly what steps 2. and 3. are about: Connecting your local project with your server repo and pushing its contents to the server. – Rahel Lüthy Jan 05 '15 at 14:07
  • look what happend in shell : http://codepad.org/3EF2yAjO. But no files in view... – Matrix Jan 05 '15 at 14:29
  • It is obviously transferring objects. Did you inspect the (hidden) `.git` folder on the server? Or try to clone it to someplace else on your local machine? – Rahel Lüthy Jan 05 '15 at 15:20
  • I need files be not hidden to deploy my app on server. So what I try to do it's just a copy of my local repo – Matrix Jan 05 '15 at 15:22
  • So you're not actually interested in setting up a git server, but just in pushing files to your app server, right? Did you try without the `--bare` then? – Rahel Lüthy Jan 05 '15 at 15:37
  • if I just `git init` on server and git push on my local, there is an error : http://pastebin.com/z5QpK8xT – Matrix Jan 05 '15 at 15:43
  • So did you try specifying a branch (as it says...): `git push origin master`? – Rahel Lüthy Jan 05 '15 at 15:49
2

EDIT: This is probably the easiest way to do this: http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/

SSH into the server and clone from your computer as you would normally clone from a server.

Basic steps would be

  1. SSH into server ssh user@server
  2. clone repo to (what is now) local storage git clone --bare ssh://user@desktop-pc/path/to/project.git (I would use git clone --bare as other wise it's not as convenient to push to it - you don't have to though)
  3. Log out of server
  4. (optional) In local (desktop) repo add the new server as a remote git remote add <remote-name> ssh://user@server/path/to/repo

This relies on your desktop running an ssh server although most linux installations will have one (usually openssh) installed as standard. You might need to check it's running.

Holloway
  • 6,412
  • 1
  • 26
  • 33
  • I have to use the IP adresse of my local machine? – Matrix Jan 05 '15 at 10:02
  • I can't connect to my local machine with ssh. there is a connexion timeout. I have many computer in my local area network. So my external IP is not enouth to identificate one computer in particular I supposed. How can I do in this configuration? – Matrix Jan 05 '15 at 10:28
  • Sorry, I assumed the server was on the same lan as your machine. I'm not sure of the easiest way to open your machine to the server. Depending on how secure the project is, you could upload to something like github, then clone it from there on the server. – Holloway Jan 05 '15 at 11:21
  • 1
    I would perform a `git init --bare` rather than a clone on the server. You won't need your local machine's IP for that. Please check my full answer below. – Rahel Lüthy Jan 05 '15 at 11:41
  • 1
    @netzwerg, You're right, see the edit I made earlier. I assumed the server would be on the same lan and have access to the local machine as that's how I have mine set up. – Holloway Jan 05 '15 at 11:43
  • the solution don't work I follow the steps (http://codepad.org/3EF2yAjO) but there is no file project at the end, only git file... – Matrix Jan 05 '15 at 14:42
  • @Matrix, as netzwerg said, you created a bare repo, so there will be no files in the working directory. Why do you want the files to exist on the server? If it's for web dev stuff (based on /var/www) [this](http://caiustheory.com/automatically-deploying-website-from-remote-git-repository/) may be of interest. – Holloway Jan 05 '15 at 14:49
0

You could mirror the git depot from your machine to your server :

on your server :

git clone --mirror git@YourComputerIp:YourRepository

Some reading : http://git-scm.com/docs/git-clone

if your local machine is not on the same network as your server, you should configure your router to route git port to your local machine, and use your public IP

Xarouma
  • 171
  • 1
  • 10