I found this post explaining how to use the GitHub tree API to update a submodule to a specific commit, and decided to use Transposit to build a GitHub webhook. I wanted to automate the process such that on commit to the submodule, the parent repository automatically updates the SHA. Here's an example of what the diff looks like: diff -git a/src/docs b/src/docs Then, in the parent repository, commit the updated SHA. Usually, this involves doing a git pull on master. The basic process is to first go to the submodule path within the parent repo and update the submodule to the new SHA. If you've worked with Git submodules, you've probably experienced the painful process of updating the submodule SHA. Unfortunately, this setup led to a pretty manual and unreliable process: changes would often go unpublished when team members would commit to the docs repo, but forget to update the submodule SHA. At Transposit, we use submodules because we want to open-source our docs repo to allow community contributions, but we want to keep the remainder of our website in a separate private repository. It has become a suitable way to present the parent and child workflow in the forom of git submodules.Git submodules allow you to nest one repository inside of another. Gitmodule has made the workflow really easier to work with different projects at a time. In this article we learned what a git submodule is and how we can use it while working with different projects. Suppose my submodule name is then run the below command like git submodule deinit -f - rishimodule To delete a submodule one can use the below commands. The -remote helps to update the existing repository without pulling it. The below command $ git submodule update -remote -merge So you can update the previous submodule in the project. In some cases you dont want to pull a submodule. If the whole command is not used the folder will be pulled but not the content. So we can see the working on the same project as in previous example. Submodule 'asign' () registered for path 'assign'Ĭloning into '/home/parth/submodules/assign'. THe below example shows how it works $ git submodule update -init -recursive To pull a submodule with its content you the below command $ git submodule update -init -recursive Working as a developer sometimes you need to pull a submodule on another project. This is usually common when you work on several checked out branches and you want to roll back to the commit tracked by parent repository. The parent repository tracks all the commits.Ī submodule update checks out the revision of all the commits that the parent repository has gone through after a pull.This is useful when you want to roll back to the current commit of the parent repository. There is always an option to use the best commit. So the above example shows adding a project submodule in my project in a folder named assign. Remote: Total 3025 (delta 0), reused 0 (delta 0), pack-reused 5257 Password for into '/home/rishivant/main/project'. git submodule add assignĬloning into '/home/rishivant/Documents/ut it assignment/assign'. This example will show you in a better way. The command to commit it is :- $ git commit -m "Added the submodule to the project." So as a consequence you will need to commit it. While adding your submodule you will find that it will be staged. They make it easy to create a connection between multiple projects that depend on one another. To add a submodule use ‘git submodule add’ and specify the url of the repository you want to add as a submodule. Submodules are links to a Git repository within a repository. 2-How to create repository with submodules ?Ģ.1 To add a submodule in a git repository. gitmodules file which contains the path of all submodules and the link to clone them. I looked at this answer and it says that both the name and the commit hash should appear as links but that does not seem to be the case for me. I cannot open the root folder of the repo in my project repo here. You can find the submodule anywhere inside the parents repository working directory.We can configure the submodule via. I recently added this github repo as a submodule in my project repo. Now this helps in tracking the changes in all the repositories from a central repository. In simple words git allows you to include other repositories into a single repository called parent repository. Sub modules provide the feature of embedding one repository into another as a sub folder. Reading Time: 3 minutes 1 – What is a Git Submodule?Īctually git provides the feature of git submodule to help projects with this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |