Last active
October 21, 2023 07:29
-
-
Save calebbrewer/5672464 to your computer and use it in GitHub Desktop.
Manage and deploy a website with Git. I am using Lunux CentOS for my server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Video on this Gist: https://www.youtube.com/watch?v=zvpLDuRY4ss&feature=c4-overview&list=UUj8_147vA3FQ1quI_CjciIQ | |
#Initialize a bare repo on the webserver. This would preferably be outside of your public website dir but if you are on a shared host you may not have that option. I like to make a folder just outside of the live folder called git. So for me it would look like this… | |
$ cd /var/www | |
$ mkdir git && cd git | |
$ git init –-bare | |
#Now you need to create a post-receive hook that will check out the latest tree from the Git repo you just setup into the /var/www/html folder where you want your website to be. You can make this whatever folder you want your code to end up in. | |
#This will create a file called post-receive in the hooks dir of the git repo. | |
$ cat > hooks/post-receive | |
#Paste this in and remember to change the GIT_WORK_TREE=/var/www/html to whatever dir you want your code in. | |
#!/bin/sh | |
GIT_WORK_TREE=/var/www/html git checkout -f | |
$ chmod +x hooks/post-receive | |
#On your workstation you will now need to add your server as a remote. | |
#in your local repo run… | |
$ git remote add liveServer [email protected]:/var/www/git | |
$ git push liveServer +master:refs/heads/master | |
#After you type the password for the user the repo on the server will contain a copy of your files and the head pointer of the repo on the server will point to the same commit as your local repo. | |
#In the future when you are ready to push changes to the web server just type… | |
$ git push liveServer | |
#The .git/config file on your workstation is where the settings for the remote are kept, so if you need to make any changes to the connection you can do it there. | |
#You can also setup an SSL key so that you don’t have to type your password when you push to the repo on the server. | |
#keep in mind that all we have done is setup a remote repo on a server, so you could go through this same setup but not checkout the files (code). This would let you use this like your personal Git repo for collaboration (like GitHub). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment