Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy a project using Git push

Is it possible to deploy a website using git push? I have a hunch it has something to do with using git hooks to perform a git reset --hard on the server side, but how would I go about accomplishing this?

like image 846
Kyle Cronin Avatar asked Nov 10 '08 21:11

Kyle Cronin


People also ask

Can git be used for a deployment?

Git deployment If you want to pull the latest version of the repo, you run git pull . If you want to share changes with others, you run git push . Since only changesets are uploaded or pulled, these operations are very fast. However, many people don't know that they can deploy with Git just as easily.

How do I push an existing project to GitHub?

In the command line, navigate to the root directory of your project. Initialize the local directory as a Git repository. To create a repository for your project on GitHub, use the gh repo create subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository.


1 Answers

I found this script on this site and it seems to work quite well.

  1. Copy over your .git directory to your web server
  2. On your local copy, modify your .git/config file and add your web server as a remote:

    [remote "production"]     url = username@webserver:/path/to/htdocs/.git 
  3. On the server, replace .git/hooks/post-update with this file (in the answer below)

  4. Add execute access to the file (again, on the server):

    chmod +x .git/hooks/post-update 
  5. Now, just locally push to your web server and it should automatically update the working copy:

    git push production 
like image 161
Kyle Cronin Avatar answered Oct 11 '22 20:10

Kyle Cronin