Subtree

  • Reference
    https://help.github.com/articles/about-git-subtree-merges/
  • Add the new remote
    git remote add -f [new_directory_name] [remote_url]
    git remote add -f databases https://ciatph@bitbucket.org/ciatph/data.git
  • Merge the remote project into the local Git project
  • git merge -s ours —no-commit —allow-unrelated-histories [new_directory_name]/master
  • git merge -s ours —no-commit —allow-unrelated-histories databases/master
  • Create a new directory /databases, copy the Git history of remote
    git read-tree —prefix=[directory_name]/ -u [directory_name]/master
    git read-tree —prefix=databases/ -u databases/master
  • Commit the subtree merge
    git commit -m “Subtree merged in /databases.”

Submodule

  1. Add a submodule with target branch (master) to track to a repository
git submodule add -b master [URL to Git Repo]
git submodule init
git commit -m "Added submodule."
git push
  1. Clone a repository with a submodule
    git clone --recursive [URL to Git Repo]
  2. Pull new updates into the submodule
cd [submodule directory]
git checkout master
git pull
cd ..
git add [submodule directory]
git commit -m "Move submodule to the latest commit in master."
git push
  1. Pull new updates into the main repository including changes in its submodules (not working quite)
    git pull --recurse-submodules
  2. Pull all changes for the submodules (alternative for #3)
    • git submodule update --remote
    • if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.
  3. Execute git commands on every submodule. i.e., (reset all submodules)
    git submodule foreach --recursive 'git reset --hard'

References

Git

1, 2, 3 - submodules
4 - subtree