CHEATSHEET FOR USING GIT FOR WEB SITES HOSTED BY BASIC SLAC WEB SERVER Greg White, 21-Nov-2019 v0.1 21-Nov-2019, First version This cheatsheet helps authors of web accessible static web pages at SLAC, to manage the files of their web sites using git, and use git to automatically publish to the SLAC web server. Three directories are relevant for developing web sites using Git at SLAC. 1. SLAC's Apache web server serves out of /afs/slac/www/. Anything under that is at the symmetrical URL address under https://www.slac.stanford.edu/. Eg This file, whose URL is: https://www.slac.stanford.edu/grp/ad/docs/model/swdev/wwwslaccheatsheet.txt, would be found at /afs/slac/www/grp/ad/docs/model/swdev/wwwslaccheatsheet.txt. 2. Git Repos. Our repos for accelerator related software, are hosted at: /afs/slac/g/cd/swe/git/repos/. Specifically, repos of web sites SHOULD be under: /afs/slac/g/cd/swe/git/repos/sites/. 3. Your development directory. Personally I clone repos from above into ~/sites/. Basic publication mechanism =========================== This section describes setting up a git repo under /afs/slac.stanford.edu/g/cd/swe/git/repos/sites/, so that it automatically publishes anything got pushed to it, into its concomitant web site under https://www.slac.stanford.edu/. This example made the web site corresponding to the URL https://www.slac.stanford.edu/grp/ad/docs/model/swdev/ Note the directory design of repos for web sites under https://www.slac.stanford.edu/grp/ad/docs/. These repos are hosted at /afs/slac.stanford.edu/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/: Setting up the repo for your web site: cd /afs/slac/g/cd/swe/git/repos/sites # Where (I propose) we keep web site golden master repos mkdir -p www.slac.stanford.edu/grp/ad/docs/model/ # Make a directory for the golden master of the repo # corresponding to its URL at SLAC. Make the repo in the right place in the directory hierarchy: cd www.slac.stanford.edu/grp/ad/docs/model/ git init --bare swdev.git # Make our golden master bare repo for the files of a # site or subsite. Make the git post-receive hook that publishes all pushed changes, directly to the web site: [Experts will note there is no ssh setup done here, which is often part of the auto publication process. That's because the repo and the publication area are both in AFS, and so accessible from the same SLAC host. So all that is needed is to tell git to where to make its work checkout (GIT_WORK_TREE).] Write the post-receive hook right in the bare repo hooks dir: cd /afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git gwt=/afs/slac/www/grp/ad/docs/model/swdev/ # Set to where git will auto-checkout pushes made to it echo '#!/bin/sh' > hooks/post-receive echo "GIT_WORK_TREE=$gwt git checkout -f" >> hooks/post-receive chmod +x hooks/post-receive #Give execute permission to the script Ensure the directory to which you want your post-receive hook to checkout any updates, exists (in the web site space). If not make it: cd /afs/slac/www/grp/ad/docs/model mkdir swdev Having completed the above steps just once, any time you git push to swdev.git, /afs/slac/www/grp/ad/docs/model/swdev/ will be automatically updated, and hence also the web site https://www.slac.stanford.edu/grp/ad/docs/model/swdev/. Basic Workflow ============== 1. Optionally, make a directory where you'll do your edit, that has the same directory structure as the web site and the repos; [greg@rhel6-64e git]$ pwd /u/cd/greg/Sites/git [greg@rhel6-64e git]$ mkdir -p www.slac.stanford.edu/grp/ad/docs/model [greg@rhel6-64e git]$ cd www.slac.stanford.edu/grp/ad/docs/model 2. Clone the repo of the web site you're interested in, If on an AFS machine: [greg@rhel6-64e model]$ git clone /afs/slac.stanford.edu/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/matlab.git Cloning into 'matlab'... warning: You appear to have cloned an empty repository. done. Or if on your own machine: git clone greg@rhel6-64.slac.stanford.edu:/afs/slac/g/cd/swe/git/repos/sites/www.slac.stanford.edu/grp/ad/docs/model/swdev.git 3. Edit files 4. Then git add and git commit. maybe in one line: git commit -am 'Removed arcfour256' 5. Finally git push. If the setup above in Basic Publication Mechanism has been done properly, the web site will update automatically. git push Iterate steps 3 (edit) to 5 (push) as much as you like.