How to update website using git

I know how to pull, commit, and push in git to update my local in repository of bitbucket, but I don't have an idea about how to update my website that's located in host using git.


Solution 1:

if the server allows you install/configure git you may like use post hooks.

Pretty much configure origin to your running host and on pushing to certain branches make it also push to origin and compile if needed.

Solution 2:

If your server has git (can allow you to install git) (you can also install a 'portable' version of git that doesn't require elevated privileges), you can 'use' git to do your deployment (in a way).

You have your dev code in a branch. Clone this repo onto your server. Branch this code with a name such as 'production'. Make all of the necessary setup changes to get your dev code to work on server (change settings files, change configuration files, .htaccess files, etc...). Now add commits to this branch and push to your repo.

In the future, when you do changes in your dev environment, you can just rebase your production branch onto the new head of the dev branch (I'd tag the current production branch with a version number just to have an easy way to go back quickly). This makes it quick and trivial to use git for deployment as you already have all of the changes necessary to move from dev to production (i have an intermediate step there of a staging branch).