How do you get your shiny new Statamic 3 site into the eyes of the eager public hordes?
Well you can use FTP. Like an animal. Upload the site to your favourite web host, set the default folder to be
/public and you're golden.
Or you can join the cool kids and start to use a more automated, and reliable, deployment process.
Git is a versioning system. Most designers like me tremble in fear at the thought of using Git, much like the approach of an account manager on a Friday afternoon.
Git is used by Statamic Pro to provide a way of keeping your local content synced with your production content. It kind of works too.
Statamic Pro means you paid for the product. Well done you. You just funded someone's family meals for another month.
Previously I hated using git. Until I started using it in Terminal. There I said it. I like Terminal. I find that a GUI just makes git more complicated that it should be.
I found it hard to find instructions for users who are solo or speak normal English rather than Ancient Geek. So here is my guide to getting Git into your life.
On macOS Git is pretty easy to install. Run
git --version. If it's not installed then you will get a MacOS installer window. If it is installed you should see the version number. Mine says
git version 2.21.0 (Apple Git-122).
Next you need to make a user. Make it global so you don't have to enter it all the time.
git config --global user.name "Jonathan Elliman" git config --global user.email "firstname.lastname@example.org"
That's it! Easypeasy.
In order to connect to a remote repository you need to create an SSH Key. This allows the local repository to talk to the remote repository without Piers Morgan listening in.
ssh-keygen -t rsa -b 4096 -C "email@example.com"
This creates a new key for you. You'll be promoted to save the key. Normally this file lives in your user's
.ssh/ folder. It's normally called
id_rsa. I didn't do anything different but you can if you're just being difficult. Secure the key with a password.
e.g. My path to the ssh-agent is
Add the newly created key to the
id_rsa file with
ssh-add -K /Users/your-user-name/.ssh/id_rsa.
Once you've done that then you can copy this key to your GitHub* account. Run
pbcopy < ~/.ssh/id_rsa.pub. In GitHub browse to
Settings > SSH and GPG keys. Add an New SSH Key, give it a meaningful title, and paste in your copied key. You may need to enter your GitHub password at this point.
Dash back to the Terminal and enter
ssh -T firstname.lastname@example.org. It should give you a reply like:
Hi ellimondo! You've successfully authenticated, but GitHub does not provide shell access.
Well done. You're now as confused as I was. But what's afoot Watson? That's about 304.8mm in modern money, Holmes.
* Other remote repositories are available.
Next up you need to initialise a repository. That's going to be your project folder. For me it's
cd ~/Sites/ellimondo/. Then type in
git init. This turns the root folder into a repository. Everything inside that folder is now mercilessly tracked by Git.
You should now have a
git.ignore file in your root. The
statamic/statamic install comes with one already. Here's mine:
*.code-workspace .DS_Store # From Statamic/statamic settings /node_modules /public/hot /public/img/containers/* /public/storage /public/vendor/statamic /storage/*.key /storage/forms /vendor .env .env.backup .env.example .phpunit.result.cache Homestead.json Homestead.yaml npm-debug.log yarn-error.log content/collections/pages/test.md
This file just tells git to ignore these files and folders.
You can now deploy to a remote repository. Most people use Github. I do too.
First up you need to make a remote repo. Go to GitHub and create a new respoitory. It will have the name
username/repository_name. e.g. Here I have
ellimondo/ellimondo_site. Make it private otherwise you are exposing licensed software to the outside world.
Now click the Copy button and copy the SSH path under Clone with SSH.
For me that's
Then in your Terminal change directory to the project folder root add the remote path with
git remote origin email@example.com:ellimondo/ellimondo_site.git.
You've added the remote path to your local git configuration. You can now push and pull from that remote repository.
Add all your existing files with
git add .. The '.' means all files.
Then commit those files to the repository.
git commit -m 'Add a meaningful or silly message here. Git will whirl away and add all your files.
Now you can push them to the remote repository with (and I am assuming you are not using any branches)
git push origin master.
origin being the path to the remote repository and
master being the default branch name. I just stick to the basics. If you don't want to type the whole command everytime then you can add a shortcut with
git push --set-upstream origin master. Now you can just type
git push. Well done, you've saved yourself 0.25 nanoseconds.
You will see git whirr away in the Terminal. You can then check out GitHub and see your files appear inside your remote repository.
You are now the Repo Man (or Woman etc)!
Git can be a pain as it's easy to panic if something goes wrong. I am only going to touch on the basics here as that's as far as my knowledge goes.
You can always check the status of git with
git status. This can help you tell if you are up to date with or have files to commit.
git pull is the opposite of
git push and it's this command that causes the greatest confusion for me. It often leads to a merge conflict. I am going to be controversial here. Do you need to use it? No? Then don't use it if you don't have to!
git fetch will pull in files but it doesn't integrate them into your local repository like
git pull does. It's more gentle. Like Fairy Liquid.
More commonly you will want to remove a file or folder from being tracked. It's easy to remove it from git without deleting the local file. add the
-r option for folders. e.g.
git rm —cached embarassing_photo.jpg git rm -r —cached folder_filled_with_saucy_pics
Now you've got your site somewhere else I suppose you are wondering how to get that onto a web server…