11/20/2023 0 Comments Github add submodule to projectSubmodule reference updated in the terminal after git status command The -recurse-submodules=on-demand command pushes all of the project modules at the same time. For each submodule commit, the project updates its reference to the submodule to maintain its connection to the correct commit. It’s super important when we build to make sure that we commit and push both the public submodule and the main project. > git push -u origin master -recurse-submodules =on-demand Push the source project *and* the public submodule to Github together. > git commit -m "first build - update submodule reference" # 8. Perform a site build and output to 'public/' directory. In our local terminal, run the following command from the project root. First, we create another repo on Github for our public site data. Let’s add our first submodule to the project! Remember, our goal is to separate the commit histories of our project source and our site build output to the public directory. To accomplish this, we have to create a second repository. However, if we do this we ignore our chance to separate public into a separately versioned repo. That would require a different setup that you can find steps for on Hugo’s Host on Github docs page. You could absolutely set up your source repo to be the host of your site using Github Pages, and you may have good reasons for doing so. Push to the remote master > git push -u origin masterĪnd there you have it! Our project source is now pushed to our Github repo. > git commit -m "committing our hugo template" # 6. Set our new Github repo as the remote for our local project # (my sample URL - ) > git remote add origin /. (If you already have a public folder in your project, delete it before doing any of this to save some headaches.) When our new empty repo is ready, go back to the terminal window and input these commands to initialize our local repo and push to Github. Hot tip: If we create a repo without a README file it’s easier to avoid accidental history conflicts when pushing a local project to a fresh repo. Sign in to Github and create a new repository. Let’s get our project versioned with Github right away! We’ll need to create two repositories on Github - one to host our source code and one to host our live site data. We’ll absolutely get to all that, but since our goal here is to use git submodules to manage the different parts of our project, it would benefit us to go through some setup steps on Github first. If you’re following Hugo’s Quick Start guide, you may be tempted to move straight on to adding a theme, running the local server, and seeing your site. So far, we’ve installed Hugo on our machine and created a new template project named hugo-gh. Move to the directory where you want to create the project. If you don't have brew installed - > /bin/bash -c " $(curl -fsSL ) " # 3. Alternatively, you can VSCode's terminal - it's great! # 2. Install Hugo and Create a Project #įirst things first, we need to install Hugo! We’ll run through the key Mac commands quickly here, but if you need any more help you can always check Hugo’s ‘Quick Start’ guide for more details or information about installing on Windows and Linux. By turning the public folder into a submodule of the main project, we can treat it as a separate entity with a separate history. After Hugo builds our site, our ‘ready-to-publish’ data gets output to the public directory of our project. In a Hugo project, most of what we see is source data - the raw files we manipulate before building our site. The submodule’s code can then be used by the main project, but the submodule maintains its own commit and branch history, which separates the projects and can be a pretty powerful thing. Git submodules allow us to reference other repos within a project, which effectively puts a project inside a project (or a repo inside a repo). Why Git Submodules? #Įvery git project is stored as a versioned code repository (a repo). Also, I work on a Mac so all of my commands are Mac-specific. To keep things simple, you can assume that I’ve stayed on the main ‘master’ branch of each git module. I’ll talk a little about branching inside our submodules later on. We’ll also go over the benefits (and drawbacks) of using submodules in our setup, and by the end of this post, we’ll have a new Hugo project hosted on Github Pages and ready for action.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |