How to use git over scp without git on the remote server

This is basically a quick adaptation of this handy tutorial to use scp instead of a usb drive. I find it useful when I have a project I want to track using git across multiple computers, and I don’t want to make it public and use github.

First, make a new directory someplace that will be your local “remote” repository. Essentially, we will use this as the remote repository and use scp to update it when necessary, and then pull from and push to it. Then cd to your working directory, and do

git clone –local –bare . /path/to/remote/repository.git

Then, add it as a remote

git remote add origin file:///path/to/remote/repository.git

Once you’ve done this, you can simply do a git push to push to this repository. Now, when you want to use this repository on another computer, first copy it to a remote server using scp:

scp –r /path/to/remote/repository.git user@host:~/git/repository.git

I like to make a git directory in my home directory both locally and on the server, to store my “remote” repositories. Whenever you update the local “remote” git repository, just use scp to copy it to the server.

When you want to get at this repository from another computer, use scp to pull down the repository, and then do a git clone or git pull to get your updated contents into your working directory.

scp –r user@host:~/git/repository.git /path/to/different/remote/repository.git

and then a git clone or git pull as necessary.
Hope this helps someone, as I was looking for something like this and couldn’t figure it out initially. It’s pretty simple but for a git newbie like me it wasn’t immediately obvious.

Advertisements

4 Responses to “How to use git over scp without git on the remote server”


  1. 1 Konstantin Simomov October 7, 2009 at 1:03 am

    So, if you have to push to really remote repository (to sync copies on two machines for expl), you have to scp hole repo back to server? You’ll transfer hole repo through the network evet if you change 1 byte in 1 file. Am I right?

  2. 3 simoncpu March 30, 2012 at 2:10 am

    You can mount your SSH server on your filesystem via sshfs, then just clone it “locally”.

  3. 4 John Cuthbert November 11, 2013 at 6:47 am

    I was looking to do something similar but under your setup I’m not sure theres any real benefit of doing so. Unless I miss understood something there.

    you say you need to do a clone or pull so surely you must have a copy of git on the server anyway?

    What I was hoping to do is something like this:
    Local Development environment is under git control.
    Client does not use git and may have other developers working on it so I want to be able to merge a non git repo with a git repo in case they change something and haven’t informed me or I forget to copy down all the files each time.

    So I guess its sort of like a GIT plugin to a FTP client I need of sorts. Anyone came across such a thing – particularly useful if it can integrate with IDEs (PHPStorm) and Filezilla.


Comments are currently closed.




%d bloggers like this: