Skip to content
Back to skills

Git Subtree Merges

ASecurity

Merge external projects into your repo without submodules.

  • 2 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 10, 2026
ai-agentsgobashgitperformance

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill git-subtree-merges --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Subtree Merges?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Subtree Merges
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-git-subtree-merges/badge)](https://www.skillsdirectory.com/skills/loopyluci-git-subtree-merges)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-subtree-merges
description: Merge external projects into your repo without submodules.
---

# Git Subtree Merges

**Trigger**: Use when incorporating an external project into your repo without submodules, or splitting out a subdirectory into its own repo.

## When to Use Subtree vs Submodules

| Aspect | Subtree | Submodule |
|--------|---------|-----------|
| Clone simplicity | Single `git clone` | `--recurse-submodules` needed |
| Pinning version | By commit SHA or tag | By commit in `.gitmodules` |
| Making local edits | Directly in repo | Must go to submodule repo |
| Contributing upstream | `git subtree push` | PR in submodule repo |
| History size | Full history merged | Pointer only |

## Adding a Subtree

```bash
git subtree add --prefix=vendor/logger \
  https://github.com/owner/logger.git main --squash

git subtree add --prefix=vendor/lib \
  https://github.com/owner/lib.git v1.0.0 --squash
```

## Pulling Updates

```bash
git subtree pull --prefix=vendor/logger \
  https://github.com/owner/logger.git main --squash

git subtree pull --prefix=vendor/logger \
  https://github.com/owner/logger.git v1.2.0 --squash
```

## Contributing Back

```bash
git subtree push --prefix=vendor/logger \
  https://github.com/owner/logger.git my-feature-branch

git remote add logger-upstream https://github.com/owner/logger.git
git subtree push --prefix=vendor/logger logger-upstream main
```

## Splitting Into a New Repo

```bash
git subtree split --prefix=src/lib --branch=lib-split

mkdir ../new-lib && cd ../new-lib
git init
git pull ../original-repo lib-split
git remote add origin https://github.com/owner/new-lib.git
git push origin main
```

## Managing Multiple Subtrees

```bash
git remote add logger-upstream https://github.com/owner/logger.git
git remote add parser-upstream https://github.com/owner/parser.git

git subtree add --prefix=vendor/logger logger-upstream main --squash
git subtree add --prefix=vendor/parser parser-upstream main --squash
```

## Pitfalls
- **Large history**: Use `--squash` to keep history clean
- **Merge conflicts**: Harder to resolve than regular merges
- **git log duplication**: Upstream commits appear twice
- **Performance**: Slower than regular git on large repos
- **No auto-updates**: Must manually pull subtree updates

## Verification
```bash
git log --oneline --all -- vendor/
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.