Deploy to the server via git push

Git is used broadly for now. Let’s look at interesting use case. Assume, we have the development machine and the live server. I’m going to hold the project in local git repo on development machine. From time to time it needs to deploy stable version to the live server as a release.

Just for demostration, I use 2 local directories /tmp/dev and /tmp/server:

mkdir /tmp/dev
mkdir /tmp/server

Then I init new repo and add some test file in the release branch on the dev side:

cd /tmp/dev
git init
git checkout -b release
vim test.txt
git add test.txt
git commit -m “initial commit”

Now I create empty repo on the server side and checkout for server branch:

cd /tmp/server
git init
git checkout -b server

Next step is to configure and pushing prepared release to the server:

cd /tmp/dev
git remote add server file:////tmp/server
git push server release

Here we use local file URL. In real situation it needs SSH one, like ssh://login@host:port/path/to/project.
Last stage is to merge just pushed version from release branch to current one (server) on the server:

cd /tmp/server
git merge release

At this point the new version is on the server side.

Usually, we host the repo of the project on github or bitbucket. Last one even allows to create private repo’s if you are not ready to share your code with the world yet. So, described above example should be treated rather as an exception then standard use case.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: