David
David

Reputation: 4895

How to create a remote repository via SSH?

I have a website that is already published on a shared server. Now I would like to use git to work on it (to implement some new features). I can use git via ssh.

How can I create a remote repository there via SSH, and then get an url to pull it on my machine, so I can work on a local workspace.

I tried

git init
git add *

But when I do git ls-remote --get-url to get the url, it shows me :

fatal: No remote configured to list refs from.

And the command git remote returns nothing.

Upvotes: 5

Views: 4360

Answers (1)

michas
michas

Reputation: 26495

You need four different things:

  • a local working copy, where you make your changes
  • a local git repository, where you commit those changes
  • a remote git repository, where you push those commits to
  • a remote working copy, where your webserver can read the changed files from

You probably already have a local working copy and a local git repository, i.e. you are able to change files and commit them.

Next you need a remote git repository to push your commits to. You can create this by something like ssh user@server git init --bare mysite. This allows you to push with something like git push user@server:mysite master.

Finally you need to make those files visible to the webserver. Probably the easiest way to do so is cloning that bare repository to the final location. You probably want to update that location after each push. To do so you can register a hook in your bare repository, which runs each time you push to it.


It gets a bit tricky, because git knows bare repositories, that do not have an associated working copy and non-bare ones which do.

You need a non-bare one to read/write the files, but you need a bare one to be able to push to, because you cannot push to a branch, that is currently checked out. - Therefore, yes, it's a bit of work to set things up.

Upvotes: 3

Related Questions