Setting up
GitHub & GitHub Pages
more setup, but most of it you only need to do once and this will allow you
to turn your local notebook-developed projects into internet-accessible websites
Install git • initialize a repository • make your first commit
- From the
Terminalcommand line, type:
git version
to check if it is already installed. - If you do not have
gitinstalled on your computer then go to git-scm and follow instructions to install it. (You may also have to installhomebrew—this is all good and doesn’t take long.) - In the
Terminal, navigate to your project folder (the first one, probably namedObservableNotebooksor similar). - Once you are in the folder, type:
git init
This initiates a local repository. - For good housekeeping, you now need to make a
.gitignorefile in your project folder. This file begins with a full-stop and, once created, is invisible-by-default when using your Finder or file system. So, if you haven’t done this before, you may need help (or googling) to create it with a text editor. Anyway, its contents should be as follows:
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.DS_Store
/dist/
node_modules/
- Now you
addall the files that git will track in your repository, using this command:
git add .
(That’s space + full-stop afteradd) - Finally, you commit all these changes to your local repository with:
git commit -m "first commit"
(This-mintroduces a ‘message’ surrounded with quotes, with a brief comment on yourcommit.)
Create an origin repo(sitory) on GitHub • push your first commit to GitHub
- If you don’t already have a GitHub account, create a free one on GitHub.com.
- Click ‘New Repository’ (usually on the upper right; you may have to click the
Repositoriestab). - Choose an unused name for the repo and then scroll down to make sure the
Visibilityof the repo ispublic. Also make sure that GitHub will not be addingREADME, .gitignore, or license. - Click ‘Create Repository’ (lower right).
- GitHub provides the next commands you need to type into your Terminal command line. Scroll down, if necessary, to:
‘…or push an existing repository from the command line’
and use the ‘copy’ button (on the right) to copy the three commands. Then go back to your Terminal command line and simplypastein these commands, hitting return once you’ve done so.
Now your local repository is set up to ‘track’ the repo on GitHub and whenever you commit and push work that you have done locally, it will be sent to GitHub (where you can share the work and collaborate). The final step is to use GitHub Pages to automatically build you an updated website whenever you push changes.
Setup GitHub Pages to build and deploy your site whenever you push new changes
- Click this link to a file that helps publish your site.
- Click the ‘Download (icon)’ button to download the file and then move it into your project directory.
- Now, from the Terminal command line, in your project directory, type these two commands:
mkdir -p .github/workflows/
mv publish.yml .github/workflows/
These two commands do the following: 1) make a directory calledworkflowsinside a (not-always-visible) directory called.githuband 2) move thepublish.ymlfile that you put into your project directory into theworkflowsfolder. - Then,
commitandpushthese changes to GitHub with these commands:
git add .
git commit -m "add publish workflow"
git push
NOTE … that these are the three commands (ideally with a different-m "message"each time) that you will issue whenever you’ve made significant changes to files in your project folder and you want to push them to your GitHub repository where they will be published.
You have added a publish.yml file to a special directory where GitHub will find it and use it to build a website once you have done a little more to set up GitHub Pages, as follows:
- Go to GitHub and open your project’s repository. Click the ‘Settings’ tab.
- Click the ‘Pages’ item from side bar on the left.
- Under ‘Build and deployment’ change ‘Deploy from a branch’ to ‘GitHub Actions’.
You may see errors at this stage but don’t worry about them (yet). The next time you make a change to your project, the site will be built and deployed. And, if you go to the GitHub repo -> Settings -> Pages again, you will see the URL for your project’s site, ready to be accessed publicly on the web. The URL will be of the form:
https://<your-user-name>.github.io/<repo-name>.