

"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Adding a submodule is accomplished using the submodule add method: We’re going to create a submodule that references a repository called web-tutorials. The repository we are going to create our submodule in is called git-submodules.įirst, we’ll need to navigate into our repository. The repository we create will have a link to all of our other tutorials. We’re going to use submodules to create a link between Career Karma’s Git repositories. Submodules are not downloaded to a repository by default.

This is because they are easy to configure and have extensive, language-specific management tools. Dependency management projects like npm and rubygems may be more convenient to use. Before you create a submodule, you should ask whether there is a better alternative available. They’re not a perfect fit for every project. The links created by submodules will make it easier to navigate around your codebase. Submodules are a good way to link plugins and themes into your code. It makes it easy to connect different repositories together which depend on each other. , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.Ī submodule is a link to a repository within a Git repository.
GITHUB ADD SUBMODULE TO PROJECT FREE
Best Free Bootcamps and Coding Training.Best Online Coding Bootcamps and Courses.# remove -allow-unrelated-histories if using git older than 2.9. Git commit -m "Removed submodule sub_repo_path in preparation for merge"Īnd finally, just merge them git fetch. Now remove the subrepo from the main repo cd.

Must be run from the root of a git repository"ĭeclare path="$(git config -f. >&2 echo "Error: No git repository found. Read -p "$(tput setaf 4)$1 (y/n) $(tput sgr0)"Ĭat &2 echo "Error: No submodule specified" # entire process and cleans up a few other corner cases.Įcho "Merge a submodule into a repo, retaining file history."Įcho " -v, -verbose Display verbose output" # post "Integrating a submodule into the parent repository", but automates the # This script builds on the excellent work by Lucas Jenß, described in his blog Git-submodule-rewrite: #!/usr/bin/env bash
GITHUB ADD SUBMODULE TO PROJECT CODE
The latest code will be maintained with bugfixes on github at, but for the sake of proper stackoverflow answer protocol, I've included the solution in its entirety below. It builds on the excellent work by Lucas Jenß, described in his blog post " Integrating a submodule into the parent repository", but automates the entire process and cleans up a few other corner cases. It's also a very easy one-line invocation that does all of the work for you.

It doesn't suffer from the git log -follow issues that the other solutions suffer from. I've created a script that will translate a submodule to a simple directory, while retaining all file history. If you still have problems with git log, try some options (e.g., -follow, -M, -C) which do better rename and copy detection. In fact, what happens here is just a renaming of many files inside one repository, and Git should automatically detect this. But it won’t cause any problems for Git.Ī big advantage of this second solution is that you can still run git blame or git log on the files which were originally in submodules. The resulting repository will look a bit weird: there will be more than one initial commit. Git rm -cached submodule_path # delete reference to submodule HEAD Git merge -s ours -no-commit submodule_origin/master # Start a fake merge (won't change any files, won't commit anything) Git remote add submodule_origin git://url/to/submodule/origin In the main module you will need to do the following: # Fetch the submodule commits into the main repository If you also want to preserve the history of the submodule, you can do a small trick: “merge” the submodule into the main repository, so that the result will be the same as it was before, except that the submodule files are now in the main repository. Git add submodule_path # will add files instead of commit reference Rm -rf submodule_path/.git # make sure you have backup!! # you need to edit this file instead of deleting! gitmodules # if you have more than one submodules, If all you want is to put your submodule code into the main repository, you just need to remove the submodule and re-add the files into the main repo: git rm -cached submodule_path # delete reference to submodule HEAD (no trailing slash)
