git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5] git-son: add command to create independent child repositories

From
EGEvan Haque via GitGitGadget <gitgitgadget@gmail.com>
Date
May 26, 2026, 16:47 UTC
Message-ID
<ec2bdddf814e018c543d0e2bb393ae8c144207aa.1779814052.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2122.git.1779814052.gitgitgadget@gmail.com>
From: Evan Haque <evanhaque1@gmail.com>

Introduce git-son, a new porcelain command that creates an independent child repository inside the current working tree. Unlike submodules, the child is not tracked by the parent; instead its directory is added to the parent's .gitignore and a "parent" remote is configured in the child pointing back to the parent's origin URL or local path.

This gives users a lightweight way to spin off a related repository that knows where it came from without the coupling that submodules impose.

The command supports two optional flags:
  --inherit    fetch the parent's history into the child at creation
  --branch     check out a specific parent branch (requires --inherit)
Assisted-by: Claude Opus 4.6
Signed-off-by: Evan Haque <evanhaque1@gmail.com>
---
 git-son.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100755 git-son.sh
diff --git a/git-son.sh b/git-son.sh
new file mode 100755
index 0000000000..a212c7b69f
--- /dev/null
+++ b/git-son.sh
@@ -0,0 +1,97 @@
+#!/bin/sh
+#
+# git-son: create an independent child repository that knows its parent
+#
+
+SUBDIRECTORY_OK='Yes'
+OPTIONS_SPEC='git son [options] <name>
+--
+inherit    fetch parent history into the son
+branch=    start the son from a specific parent branch
+'
+
+. git-sh-setup
+require_work_tree
+cd_to_toplevel
+
+inherit=
+branch=
+while test $# -gt 0
+do
+	case "$1" in
+	--inherit)
+		inherit=1 ;;
+	--branch)
+		shift
+		branch="$1" ;;
+	--)
+		shift; break ;;
+	-*)
+		usage ;;
+	*)
+		break ;;
+	esac
+	shift
+done
+
+name="$1"
+test -n "$name" || usage
+
+if test -n "$branch" && test -z "$inherit"
+then
+	die "fatal: --branch requires --inherit"
+fi
+
+parent_dir="$(pwd)"
+parent_remote="$(git remote get-url origin 2>/dev/null)" || parent_remote=
+
+if test -e "$name"
+then
+	die "fatal: '$name' already exists"
+fi
+
+mkdir "$name" || die "fatal: could not create directory '$name'"
+
+if ! echo "$name/" >> "$parent_dir/.gitignore" 2>/dev/null
+then
+	rm -rf "$name"
+	die "fatal: could not update .gitignore"
+fi
+
+cd "$name" || die "fatal: could not enter directory '$name'"
+
+if ! git init
+then
+	rm -rf "$parent_dir/$name"
+	die "fatal: could not initialize repository in '$name'"
+fi
+
+if test -n "$parent_remote"
+then
+	git remote add parent "$parent_remote"
+else
+	git remote add parent "$parent_dir"
+fi
+
+if test -n "$inherit"
+then
+	git fetch parent || die "fatal: could not fetch from parent"
+	if test -n "$branch"
+	then
+		git checkout -b "$branch" "parent/$branch" ||
+			die "fatal: could not checkout branch '$branch'"
+	else
+		git checkout -b main parent/HEAD 2>/dev/null ||
+			git checkout -b main "parent/$(git remote show parent | sed -n 's/.*HEAD branch: //p')" 2>/dev/null ||
+			echo "warning: could not determine parent HEAD, starting empty"
+	fi
+else
+	echo "# $name" > README.md
+	git add README.md
+	git commit -q -m "Initial commit"
+fi
+
+echo ""
+echo "Created son repository '$name'"
+echo "  parent: ${parent_remote:-$parent_dir}"
+echo "  inherit: ${inherit:-no}"
-- 
gitgitgadget
Previous: Evan Haque via GitGitGadgetNext: Evan Haque via GitGitGadget
Message 2 of 9 in “git son: add command to create independent child repositories”
  1. 0/5 git son: add command to create independent child repositoriesEvan Haque via GitGitGadget, May 26, 2026
  2. 1/5 git-son: add command to create independent child repositoriesEvan Haque via GitGitGadget, May 26, 2026
  3. 2/5 git-son: register in Makefile and meson build systemEvan Haque via GitGitGadget, May 26, 2026
  4. 3/5 git-son: add to command list as mainporcelainEvan Haque via GitGitGadget, May 26, 2026
  5. 4/5 git-son: add documentationEvan Haque via GitGitGadget, May 26, 2026
  6. 5/5 git-son: add testsEvan Haque via GitGitGadget, May 26, 2026
  7. Ben KnobleMay 26, 2026
  8. Claus SchneiderMay 29, 2026
  9. Junio C HamanoJun 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.