When building this blog, I read a lot about Gatsby. One question that I stumbled upon a few times in various forums, was how to keep your website up to date with the starter you selected for your project. The answers were quite short like: “use git merge”. Here is a step-by-step guide for those unfamiliar with Git and merging. For this example, I will be using the official gatsby-starter-blog repository.
- Open your terminal of choice and navigate to your website’s git repository.
- Type this command to add the starter repository as “upstream”. Remember to change the URL to the starter you used.
git remote add upstream https://github.com/gatsbyjs/gatsby-starter-blog.git
- Open your shell and navigate to your repository. Check that you are in the branch you want to sync.
- Run the command to get the latest code from upstream:
git fetch upstream
- Then this command to do the merge:
git merge upstream/master
“master” can be changed to another branch on the upstream if needed/wanted.
If you changed a lot of the code, there might be conflicts that needs to be resolved. That’s too much to cover in this blog, but there is plenty of guides out there that will help you handle the merge conflict.
That’s it, your local branch is now updated with the freshest code from the starter. Verify that everything is behaving like expected, and do a push to your own repository :)