All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Evan Haque via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Evan Haque <evanhaque1@gmail.com>, Evan Haque <evanhaque1@gmail.com>
Subject: [PATCH 1/5] git-son: add command to create independent child repositories
Date: Tue, 26 May 2026 16:47:27 +0000	[thread overview]
Message-ID: <ec2bdddf814e018c543d0e2bb393ae8c144207aa.1779814052.git.gitgitgadget@gmail.com> (raw)
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


  reply	other threads:[~2026-05-26 16:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 16:47 [PATCH 0/5] git son: add command to create independent child repositories Evan Haque via GitGitGadget
2026-05-26 16:47 ` Evan Haque via GitGitGadget [this message]
2026-05-26 16:47 ` [PATCH 2/5] git-son: register in Makefile and meson build system Evan Haque via GitGitGadget
2026-05-26 16:47 ` [PATCH 3/5] git-son: add to command list as mainporcelain Evan Haque via GitGitGadget
2026-05-26 16:47 ` [PATCH 4/5] git-son: add documentation Evan Haque via GitGitGadget
2026-05-26 16:47 ` [PATCH 5/5] git-son: add tests Evan Haque via GitGitGadget
2026-05-26 21:27 ` [PATCH 0/5] git son: add command to create independent child repositories Ben Knoble
2026-05-29 12:35   ` Claus Schneider
2026-06-01  5:33 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ec2bdddf814e018c543d0e2bb393ae8c144207aa.1779814052.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=evanhaque1@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.