![]() ![]() The commit history will include commits for the main project along with the code that we have pasted. We can always copy and paste the code between the two projects but doing this makes it very difficult to understand the project and manage the commit history.We also use the concept of submodules when using external libraries for our project.Some of these components may be complex enough that we need a separate Git Repository to manage them along with using them in our main project. Submodules are mostly used when we are working on a large-scale project that has a lot of different components.We can also use this embedded repository as a Submodule for various other repositories without creating new files from scratch for each repository. This embedded Git Repository can be managed independently and will have its own Git workflow. SubmoduleĪ Submodule is a Git Repository inside another Git Repository. Let's learn more about Submodules and how to use them in Git. But this approach is not the most efficient one. We can simply copy and paste the code needed from this external repository into our main project. A lot of times the main project will need code from some other external repository or library. This Git Repository is called the parent of the Submodule. However, you might find you have to manually merge if changes conflict.A Submodule is a Git Repository that is a subdirectory of another Git Repository. One could hope that any changes upstream will not conflict with yours so it’ll be simple to merge the changes in. I’ve not yet had the need to do this but on any active themes, there will obviously be changes you’ll likely want to pull into your theme. Step 5: merge changes from original theme The “Git Submodules basic explanation” gist from gitaarik has more details. Luckily, after following Step 3 it’s a very simple process! You just treat it like any other change: add, commit and push. " to discard changes in working directory ) (commit or discard the untracked or modified content in submodules ) modified: themes/Mainroad (new commits ) no changes added to commit (use "git add" and/or "git commit -a" ) " to update what will be committed ) (use "git checkout. (new commits) - changes in your submodule were committed.(modified content) - which means you’ve modified your submodules content but have not committed those changes to the submobule (follow Step 3).The way this will show up is when you do a git status from your main website repo, in the “Changes not staged for commit” section you will see your theme submodule listed and one of two statuses: So you need to update where the main repo’s submodule commit HEAD points to. But in Step 3 you made changes and committed them. In the case of the initial adding of the submodule, it points to the head of the submodule. In your main hugo website repo, the submodule tracks the latest submodule commit you explicitly checked in. Step 4: update main repo with latest theme commit " to unstage ) new file: layouts/partials/categories.htmlįrom here you do your normal git workflow like status, add, commit and push. Your branch is up-to-date with 'origin/master'. Using your terminal app, cd into the themes directory of your website and run git submodule add with the URL of your forked repo, e.g.: We’re now ready to add the theme to our Hugo website. Step 2: add the forked repo to your website From that point forward, your interactions with the theme will be through your fork of the repo (e.g. Note, this assumes you have a github account and are logged in. Once you visit the theme’s webpage, follow the link to it’s github repo and fork the repo into your account. Step 1: Fork your targeted themeįor this blog, we’ll target the Mainroad theme. As needed, git pull changes from the original theme repo, merging changes if there are conflictsīelow is a step by step with examples (so I can refer back to it!) with the assumption that you are using git for version control on your hugo website.Update my main website repo to the last theme commit.Tweak the theme and track the changes with git into my forked repo.Add the theme to my hugo site with git submodule.Fork the theme I want into my github account.The current way I approach this is as follows: It then gets tricky over time to merge changes from the master repo into your theme without losing any of your edits. Once you make the edit, you can’t issue a Pull Request because this is specific to you. However, you will likely run into an issue where you want to make an edit to the theme only for your website. This works, makes sense and is the most common install instructions from the theme authors. When I first started tinkering with Hugo for static website generation, I would find a Hugo theme that I like, cd into my themes directory and would simply git clone the repo into my website.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |