And the PATH might not be what it would normally be when you’re logged in, so referring to executables by their full path can be a good idea too. Just beware that the “working directory” that the script runs in might not be where you think.
The post-receive script you already have is the perfect place to do this.
GIT CREATE BRANCH FROM DEPLOY INSTALL
Run Tasks After Deploy with Gitīut maybe there’s more you wanted to do, like restart a server, or run npm install to sync up packages, or some other thing. Then, log in to your server and make sure the project files were checked out in the /var/www/deployed_project location (wherever you put them). Assuming everything is working right, you should see git push up the files, and it shouldn’t print any errors. (You can verify that the remote was added correctly by running git remote -v) Try it Out! The second command is what binds your master branch to the live remote, so when you run git push, git knows where to push. The name “live” can be whatever you want (“prod”, “production”, “deploy”, etc.). Git remote add live git push -set-upstream live master The “.git” at the end is not required, but it’s a good reminder that this directory is not a regular project. Doesn’t matter where this goes, as long as you have permission to write to it. Add the server as a “remote” to the git repo, using the path to the bare repo on the serverĬreate a bare git repo on the server.We can customize the post-receive hook to do extra stuff too: install packages, run a build, restart a service, etc.A post-receive hook in there will check out the files into a “worktree” (a separate folder, deployed_project in the diagram).The bare repo will not have our actual project files, which isn’t terribly useful, so….Look at the commits made in the branch and look at the pull request that merged the branch. Creating feature branches for all your changes makes reviewing history simple. Even small fixes and changes should have their own feature branch. We’ll create a “bare” git repository, to receive the deployed files ( bare_project.git) Git branches are inexpensive to create and maintain.Here’s a rough diagram of what will happen with this setup: But it’s using git to do the deploy, so it’s a step above just copying files, because you’re deploying a specific commit (not just whatever files are laying around). You don’t need to set up or sign up for any services. On the other, more modern side, there’s full-blown continuous deployment systems like CircleCI. On one end of the spectrum is copying files with scp or rsync or even FTP. The goal: when you run git push, deploy the latest master branch to the server. Maybe your server is on DigitalOcean, or AWS, or in your basement. Maybe the repo is kept in GitHub, maybe not.
So you’ve got a local git repository, and you want to deploy it to your own server.