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

Solution 1:

git remote add origin [email protected]/home/jonas/code/myproject.git

When using SSH, remote repository addresses can be expressed in two ways. One using absolute paths and one using relative paths from the users home directory. You've mixed them up.

The corrected command would be one of the following.

git remote add origin [email protected]:code/myproject.git
git remote add origin ssh://[email protected]/home/jonas/code/myproject.git

Solution 2:

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.

Solution 3:

First thing I notice is that you're missing a ':'. Should be git remote add origin [email protected]:/home/jonas/code/myproject.git

Solution 4:

I normally create a bare repository locally and then scp that repository to the server when I'm setting up a remote repository.

For example,

cd c:\gits
git clone --bare c:\path\to\local\repository\some_project

which creates some_project.git.

Then,

scp -r some_project.git [email protected]:/path/to/remote/gits/.

enter your password or maybe you already have public/private key access working.