Home > bash > deploy a git project to a remote host

deploy a git project to a remote host

You have a project that you develop on your local machine. You want to deploy it (upload) to a production server.

For instance, you have a homepage and you want to upload it to your university server.

I assume your project on the local machine is stored in a dedicated folder. Turn this folder into a git repository. Example:

$ cd /home/jabba/projects/homepage
$ cat index.html
Awesome homepage v0
$ cat .gitignore
$ git init
$ git add .
$ git commit -m "initial commit"

We also need an uploader script called deploy.sh :

git ls-files -z | rsync --files-from - --copy-links -av0 . --rsh="ssh -p$TO_PORT" $TO_HOST:$TO_DIR

Just launch the script and it will copy all the checked in files to the server.

However! If you remove some files on your local machine, this script won’t remove them from the remote host. That is, you will have to delete files which got removed from the project.

This tip is from here.

Related work

  • Using Git to manage a web site (Shortly: you have a local git repo with your project. You create another git repo on the remote host and you push changes to this remote git repo. A customized post-receive hook will copy everything to the specified destination folder.)
Categories: bash Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: