how to auto deploy code via git

The objective of this script is to deploy git code to ftp directory. We need to create a script file on ftp.

git_deployment.php is the file name in which the deployment code would be placed.

?secret_key=XYZ is the secret key which needs to be place in deployment code file.

Now open you ftp and create file with name as of url mentioned above. “git_deployment.php“. Open the file and place the code below. You need to change the variables in this file $repo_url, $branch_name, $username, $password, $secret_key.

You can download the code via git repo also or use this code.

You can directly hit the url to update the code on ftp or you can create a hook in your git service provider.  I assume that you have setup the git repo on Now we will create a hook in gitlab web application. We will put the url under web hook section of that repo.

You can choose when you want to trigger the hook. Eg on push Event, Merge Request Event, etc

Please add the line in your code .htaccess so that no one can access the .git folder which has all the files and configurations.