![]() ![]() Just add and commit as you normally would to create and push the parent repository to GitHub. #GIT ADD REMOTE REPOSITORY TO A SUBDIRECTORY UPDATE#You can just use the general submodule update command: $ git submodule update You don't need to specify the latest commit explicitly. If you want to update the commit of the submodule, don't worry. You can also create branches and track commits in your submodules by adding -update to your submodule update command: $ git submodule update -remote Update submodule commitsĪs explained above, a submodule is a link that points to a specific commit in the child repository. To initialize an existing Git submodule: $ git submodule init To add a child repository to a parent repository: $ git submodule add To pull all changes in submodules: $ git submodule update -remote Create repositories with submodules $ git clone -recursive -jobs 8 Pull submodulesīefore running or building the parent repository, you have to make sure that the child dependencies are up to date. $ git submodule update -init -recursive -j 8 These tools were created to support code-sharing development workflows on a more modular level, aspiring to bridge the gap between the Git repository's source-code management (SCM) and the sub-repos within it. What if you could put one project within another using a single command? What if you could just add the project as a child to any number of projects and push changes on the go, whenever you want to? Git provides solutions for this: Git submodules and Git subtrees. This would create redundancy and inconsistency in the parent repositories and make it difficult to update and maintain the child project. But, what if you want to use the same child project in many parent repositories? It wouldn't be feasible to copy the child project into every parent and have to make changes in all of them whenever you update it. The traditional method is just to copy the project to the parent repository. Suppose you want to use a single project as a child project inside a repository. eBook: An introduction to programming with Bash.Try for free: Red Hat Learning Subscription. ![]() I have no doubt there is an easier way to do this, but at the moment, it’s a procedure that has worked for me. I discovered the status variable by using set -x.įinally, the /tmp/filter.log gives me confidence that I know what has changed and what hasn’t changed, before I finally rewrite the original repo using git push origin -force. If any evaluation of returns a non-zero exit status, the whole operation will be aborted. The variable $status is used internally by Git to cause the behaviour documented in git help filter-branch: Obviously, its purpose is to rewrite the history, moving the files from their original locations in the history to their new locations in their new repo. Status=0 # tell tree-filter never to fail ![]() Mv $i $subdir || echo "ERR: mv $i $subdir failed" If & thenįiles=$(git ls-tree -name-only $GIT_COMMIT) Next, read the commits from the root of repo2/master and place the files resulting from them under subdir: Naturally, the object of the git merge command, repo2/master, means “the master branch of the Git repo at the remote named ‘repo2’”. The command has been taught not to allow this by default, with an escape hatch -allow-unrelated-histories option to be used in a rare event that merges histories of two projects that started their lives independently. “git merge” used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. Since Git 2.9, the default behaviour of git merge has changed: This is so that we can modify the tree using the read-tree command below.Ī note about the -allow-unrelated-histories option. The -no-commit option says to perform the merge but pretend the merge failed and not autocommit, to give the user a chance to inspect and further tweak the merge result before committing. There should be a message printed to the screen, “Automatic merge went well stopped before committing as requested”. ▶ git merge -s ours -no-commit repo2/master -allow-unrelated-histories ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |