A short example of using subtree for stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.4 KiB

9 years ago
9 years ago
9 years ago
  1. HOWTO use Git subtrees, I kinda think
  2. =====================================
  3. structure of this repo
  4. ----------------------
  5. This was created with:
  6. mkdir libs
  7. git subtree add -P libs/Big_Easy_Driver --squash git@github.com:sparkfun/Big_Easy_Driver.git master
  8. git subtree add -P libs/Adafruit-PiTFT-Helper --squash git@github.com:adafruit/Adafruit-PiTFT-Helper.git master
  9. You could also do the same thing by creating a named remote first:
  10. git remote add Adafruit-Pi-PiTFT-Helper git@github.com:adafruit/Adafruit-Pi-PiTFT-Helper.git
  11. git subtree add -P libs/Adafruit-PiTFT-Helper --squash Adafruit-Pi-PiTFT-Helper master
  12. `master` here could be a branch or a specific commit.
  13. (Notice how in the `subtree add`, I used the named remote instead of
  14. `git@github.com:adafruit/Adafruit-PiTFT-Helper.git`. This can be convenient,
  15. but it will only exist on a local copy of the repo, so it's one extra layer of
  16. confusion when explaining to people.)
  17. There's an `update_subtrees.sh`. It looks like this:
  18. #!/usr/bin/env bash
  19. git subtree pull -P libs/Big_Easy_Driver --squash git@github.com:sparkfun/Big_Easy_Driver.git master
  20. git subtree pull -P libs/Adafruit-PiTFT-Helper --squash git@github.com:adafruit/Adafruit-PiTFT-Helper.git master
  21. The reason this is in a script is that every `git subtree` command pretty much
  22. requires a prefix, a remote, and a ref. This is too much to expect anybody to
  23. remember without googling. Trust me, you'll forget it an hour after you set
  24. up the subtree the first time. If you don't put it in a script, at least
  25. document all the commands you use in your README.
  26. ![update_subtrees.sh](/imgs/update.gif?raw=true)
  27. I have tested this on Debian. It would _probably_ run on Windows in a git
  28. shell (assuming Bash), but I haven't tried that yet.
  29. what?
  30. -----
  31. Ok, so first, **why** subtree?
  32. Lots of people I know (especially in the hardware community) seem to be dealing
  33. with dependencies between repositories lately.
  34. `git` is actually quite bad at handling this problem, to date. In fact, I'm not
  35. sure if there exists an otherwise usable VCS that's any _good_ at it. It just
  36. doesn't seem to be very much part of the model for anything. (Somebody tell me
  37. if I'm wrong about this.)
  38. There are two out of the box solutions that I'm aware of:
  39. - submodules
  40. - subtrees
  41. Of these, submodules are probably better documented and have more first-class
  42. UI. They also seem to break things a lot and confuse users pretty badly.
  43. Here's [the relevant google search][should]. I have had a real bad time with
  44. submodules, but this isn't meant as a polemic. There may be use-cases for
  45. submodules, and they may be improving as git is developed.
  46. Anyhow, subtrees: Subtrees are a fundamentally pretty different abstraction.
  47. Rather than pointing at some remote, they copy the contents (and optionally
  48. history) of a remote repository. Advantages:
  49. - users don't have to initialize anything or clone with `--recursive` to
  50. get dependencies - code's just there.
  51. - if you use `--squash`, you just wind up with one commit pointed at the
  52. target ref.
  53. - I'm guessing it's less likely to blow up in your face with a branching
  54. workflow, but who knows.
  55. Here are some writeups:
  56. - https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt
  57. - http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/
  58. - https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844
  59. Good luck.
  60. [should]: https://www.google.com/#q=should+i+use+git+submodules