简体   繁体   中英

Using GIT to clone from a windows machine to a linux webserver (in house)

OK, I am looking for a way to use GIT to keep a web site up to date between my local machine (git repository) and my web site (git clone of repository).

I have initialized the repository (on windows 7 machine) and added all the files to the repo on my local machine. I now need to get the repo to the webswerver (a linux-based machine). I can access the webserver via putty and ssh. How do I go about cloning the repo into the appropriate directory to serve the web site?

I have tried the following from my linux based machine: git clone git+ssh://myuser@10.1.0.135/d/webserver/htdocs/repo

I keep receiving a connect to host 10.1.0.35 port 22: connection time out

Both machines are in house with the webserver being outside of the network on a different IP range (outside of firewall). I came from subversion and can easily svn commit/update to and from the webserver and my machine without issue.

Thanks for any guidance on this!

The best resource I've found for doing this is located here .

The problem I had was that issuing a git clone from the *nix environment using the above suggestions was unable to find the path to the repo properly.

I was able to fix this by starting the git daemon with the --base-path and --export-all params.

So, from the windows box:

git daemon --base-path=C:/source/ --export-all

Then from the *nix box (mac in my case):

git clone git://<local ip>/<project name>

My directory structure on the windows box is:

c:\source\<project name> - this is where the .git folder lives

Here is a walkthrough someone else did. It goes step by step showing how to do what you want.

The IP address 10.1.0.135 is reserved for private networks, which means that it only refers to your local Windows computer when used within your home network. If you're running the git clone command with that address on your server, 10.1.0.135 refers to a completely different computer, which explains why the connection isn't working.

Here's my suggestion: instead of trying to clone the repository on your home computer, first create an empty repository on the server

server$ git init /path/to/repository

and then push changes from your computer to the server's repository

home$ git remote add website ssh://myuser@server/path/to/repository
home$ git push website

You can call the remote something other than "website" if you want.

For slightly more advanced usage, I've written a blog post explaining how to set up staging and production servers and maintain them with git. If you don't want to deal with a staging server, though, I also link to a couple of tutorials about a simple two-repository setup to manage a website with git, which is basically what it sounds like you're looking for.

Sounds like your windows 7 machine (in particular, port 22) may not be accessible from outside of the firewall. With subversion, the webserver is likely accessible to both machines. Also, the IP for your Windows machine is a non-routable IP, which means your firewall is likely also NAT'ing your internal network.

You could approach this by opening port 22 in the firewall, or setting up port-forwarding in the firewall to point to your Windows machine. But you should probably create the git repo on the server, then clone from that to your Windows machine instead. You could use scp -r to get that initial repo on the server, though someone with more git experience may be able to tell you a better way.

Good idea to do this with Git, if you need to check it into a version control system anyhow.

Just wanted to mention you could also look at the rsync utility - eg google "Rsync Windows" brings up some nice results.

Rsync is specifically made for keeping directory trees in-sync across machines. And it does it smart, not transfering files which are already on the other side, and you can use compression.. it has tons of features, and is typically used in UNIX production environments. There are ways to run it also on Windows.

In any case:

Check your firewall settings on both machines - the relevant ports need to be open. In your case port 22 is probably blocked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM