开发者

How to I combine two separate Git repositories?

I have cloned a git repo which has my emacs config files in. I would like to add pylookup in a subdirectory. What is the correct way to do this?

Below are the options I can think of.


  1. If I clone it into ~/.emacs.d/pylookup/ and add that folder to my emacs repo, will that update properly when I do开发者_Python百科:

    cd ~/.emacs.d/pylookup/
    git pull
    cd ~/.emacs.d
    git commit -a -m "updates to pylookup"
    git push
    

    i.e. when I pull those changes on my other machines will I have the new version of pylookup?

  2. Do I simply get my emacs repo to ignore pylookup/* and update it on every machine whenever pylookup is updated. This would get annoying if there was a few repo's and a few machines but I can live with it.

  3. Is there some smart tricks with git submodule. If so could you provide an explanation I didn't really understand the documentation. How would I pull changes for emacs and for pylookup.

  4. Do I go with answer 2 but make a script to update all sub-repos. If I did that I could run that once on each machine every time pylookup changed.


Couple of possible related posts.

  • Combining multiple git repositories
  • Create a git repository that contains another git repository


If you create a Git submodule:

$ git submodule add git://github.com/tsgates/pylookup.git pylookup
$ git submodule init pylookup
$ git submodule update pylookup

Let's say there are some changes to pylookup and you want to get them:

$ cd pylookup
$ git pull origin master
$ cd ..
$ git add pylookup
$ git commit -m "Track new commit of pylookup"


I used subtree merge with a similar problem - http://git-scm.com/book/en/Git-Tools-Subtree-Merging. Something like:

$ git remote add -f pylookup /path/to/pylookup
$ git merge -s ours --no-commit pylookup/master
$ git read-tree --prefix=pylookup/ -u pylookup/master
$ git ci -m "merging pylookup into pylookup subdirectory"

Good guide here: http://jasonkarns.com/blog/merge-two-git-repositories-into-one

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜