Question

I have a git repo where a group of developers and I are collaborating on project code. occasionally, we'd like to copy the git repo to a VPS (setup as Linux server) that has an external IP address (w.x.y.z).

I can go into an SFTP client and navigate up the folder hierarchy to the server root and then navigate down to /var/www/ (server web root) to drop my files in but I'd like to deploy to the server through the command line instead.

My goal is to configure the Linux server as a remote git directory but don't know how to go about navigating up the file hierarchy to have git recognize that the remote branch repo needs to go into /var/www/.

Brief search has uncovered git remote add origin username@w.x.y.z then use git push origin.

It seems that connecting this way to w.x.y.z will land me at the home folder of 'username', not the root web directory (/var/www/) when accessed via the browser.

Does anyone have insight into how I should go about setting up a remote directory for deploying a git repo to a "production" server?

Was it helpful?

Solution

You appear to be doing this a rather non-obvious way. I think what you want to do is copy the git repo to somewhere else (the vps server). The standard way to achieve this is git clone.

In your /var/www/ directory or an appropriate subdirectory thereof, do:

git clone [URL-FROM-GITHUB]

That will clone the git repository to your VPS. You can then update it with

git pull

could script this with

ssh my.vps.server 'cd /var/www/whatever && git pull'

However, normally you don't want the entire project in '/var/www/...' because that would also put stuff you did not mean to deploy there, e.g. the .git directory. Hence perhaps better to clone the repo within your home directory, and make a small script to rsync the appropriate /var/www/ directory against your repo, using --exclude to remove files you don't want, or just rsync-ing a subdirectory of the repo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top