%% date:: [[2021-03-03]], [[2023-05-06]] parent:: %% # [[Submodules vs subtrees vs worktrees in Git]] In [[Git]], there are three types of subdivisions of a repository: - [[Submodules in Git|Submodules]] - [[Subtrees in Git|Subtrees]] - [[Worktrees in Git|Worktrees]] Subtrees and submodules let you *nest* a subproject within a project. These can be used, for example, when the subproject is a dependency of the project. Worktrees, on the other hand, let you work on two different branches at the same time within the same repo. [^01] > A submodule is a pointer to a commit, usually in another repository. > A subtree is a directory in your repository. > A worktree is another checkout of your repository that shares the same `.git` folder. [^02] ## When should you use what? - When your project has a dependency that is updated in another repo: *Submodule* - When your project has a dependency that you maintain in the same repo: *Subtree* - When you want to work on different features or fixes at the same time for the same repo: *Worktree* - When you want to push a subdirectory, not the whole directory, to a branch on the same repo: *Supposedly subtree, but I've had better success with a worktree* (see [Presentation slides as code](https://nicolevanderhoeven.com/blog/20210302-presentation-slides-as-code/)) [^01]: [chrismorin on Reddit](https://www.reddit.com/r/git/comments/4o1s31/eli5_whats_the_difference_between_git_worktree_vs/d4924w5/) [^02]: [LB-- on reddit](https://www.reddit.com/r/git/comments/4o1s31/eli5_whats_the_difference_between_git_worktree_vs/d49tlif/)