使用 git subtree 共享代码

假设 shared 是要共享的目录

添加远程分支
git remote add shared [email protected]:wangjile/shared-code.git

git subtree push --prefix shared shared master

在要用的地方
git fetch shared
git subtree add --prefix shared shared/master
git subtree pull --prefix shared shared master --squash

可选

git subtree split --prefix shared --rejoin
会生成一个空的 commit 作为 base,
可以避免把所有的 commit loop 一遍

git subtree split --prefix shared -b backport
把改动切成分支,想咋改都行

参考

  • the alternative to Git submodule
  • Using Git Subtree to Share Code Between Rails Applications
  • Why does 'git subtree push' always list hundreds of commits?](http://stackoverflow.com/questions/26928299/why-does-git-subtree-push-always-list-hundreds-of-commits)

你可能感兴趣的:(使用 git subtree 共享代码)