Search code examples
gitgit-clonegit-remote

Git: what is project.git and how to clone it via SSH from an owned domain


This is very stupid (question or git system or git documentation - I still haven't decided).

I have ssh access to client's server. There is a website domain.com, and there is git repository, they are under /var/www/html. In git config file there are no remotes, but should they be there? Git itself is installed, I can list history for example.

And subject is the question: at local pc how can I push and pull from that repository? Or am I misunderstanding something?


Solution

  • It appears you have a remote repository you'd like to work with from your local machine.

    Cloning

    You'll need a copy of that repository in your local machine, otherwise how are you going to work with it, right? Let's have a look at the docs:

    The SSH Protocol

    A common transport protocol for Git when self-hosting is over SSH. This is because SSH access to servers is already set up in most places — and if it isn’t, it’s easy to do. SSH is also an authenticated network protocol and, because it’s ubiquitous, it’s generally easy to set up and use.

    To clone a Git repository over SSH, you can specify an ssh:// URL like this:

    $ git clone ssh://[user@]server/project.git
    

    Or you can use the shorter scp-like syntax for the SSH protocol:

    $ git clone [user@]server:project.git
    

    In both cases above, if you don’t specify the optional username, Git assumes the user you’re currently logged in as. [source]

    In your case, the command should be ssh://[email protected]/var/www/html/.git1, as we were able to hammer out in the comments.

    This will clone that repository locally and will set your local clone to point to that repository as remote.

    Man, the point is that I have already read that git doc and all related stuff. There is everywhere project.git at the end of command, which is repo name I guess.

    Now I see the confusion. Typically, a git repo locally is cloned as a working copy. A working copy has a root dir and, inside, an hidden .git folder. However, this is not always the case, as you may create a repository as bare. It is a convention (not mandatory as far as I know) to init a bare repository as repo.git. A bare repository doesn't possess the hidden .git folder and, as such, ".git" is appended to the root folder name. This is why you often see project.git in the git documentation.

    In git config file there are no remotes, but should they be there?

    On the remote, probably no, there shouldn't be any. This isn't a general rule (on the contrary) but from your description should be the best answer. On you local clone, on the contrary, there should be one.


    1) This tells us two things: if there is a folder .git in that location, then your root folder is html and everything inside of it is under version control. As a consequence, your remote is set up as a working copy. If this is not the case, since you say you are able to run some git commands in the remote, you might want to check if the remote is bare and troubleshoot the root of that repo using these tools.