Search code examples
gitsshrepositorygit-remoteubuntu-server

How do I add a remote Git repository to an Ubuntu Server?


I have created a Git repository on my Desktop machine (Windows 7) with:

git init
git add <all my files>
git commit -m "added my files"

Now I have installed a new Ubuntu Server 10.10 on a machine on my LAN and installed OpenSSH. My home directory is /home/jonas and I created a directory ~/code/ to contain my projects. I can log in to the Ubuntu Server from Windows 7 with Putty.

I installed Git on the server with sudo apt-get install git

Adding a remote repository

Now I want to add my Git repository on my Desktop to the Server. I tried to follow the instructions from Pragmatic Version Control Using Git.

From my Desktop I run these commands:

git remote add origin jonas@192.168.1.10/home/jonas/code/myproject.git
git push origin master

But I got this error message:

fatal: 'jonas@192.168.1.180/home/jonas/code/myproject.git' does not appear to be
 a git repository
fatal: The remote end hung up unexpectedly

What is the problem? How do I create the remote repository?


As PerfectlyNormal suggested, I added a : in the address. Now it worked better, and I had to type my password to the server, but then I got a similar error message:

fatal: '/home/jonas/code/myproject.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

Do I have to initialize a Git repository on the server before I can git push to it?


Solution

  • Did you setup the repository on the remote server? You need to run

    mkdir -p /home/jonas/code/myproject.git
    cd /home/jonas/code/myproject.git
    git init --bare
    

    on the server in order to set it up. I recommend taking a look at how to setup a git server in the free ProGit book.