{"thread":{"id":"32225","subject":"Re: [PATCH v4 0/4] git-submodule add: Add --local-branch option (summary)","startedAt":"2012-11-28T13:09:03Z","lastAt":"2012-11-28T19:30:29Z","messageCount":5,"participants":["W. Trevor King"],"isPatch":true,"patchVersion":4,"patchTotal":4},"messages":[{"id":"204156","messageId":"20121128130903.GB15786@odin.tremily.us","threadId":"32225","inReplyTo":"20121128063107.GA7189@book.hvoigt.net","subject":"Re: [PATCH v4 0/4] git-submodule add: Add --local-branch option (summary)","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2012-11-28T13:09:03Z","receivedAt":"2012-11-28T13:09:03Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"On Tue, Nov 27, 2012 at 09:42:05PM -0500, W. Trevor King wrote:\n> On Wed, Nov 28, 2012 at 12:28:58AM +0100, Heiko Voigt wrote:\n> > https://github.com/hvoigt/git/commits/hv/floating_submodules_draft\n> \n> I looked over this before, but maybe not thoroughly enough ;).\n\nHeiko pointed out that I likely hadn't looked at this branch at all,\nwhich is true.  I'd confused it with his earlier:\n\nOn Fri, Nov 09, 2012 at 05:29:27PM +0100, Heiko Voigt wrote:\n> https://github.com/hvoigt/git/commits/hv/floating_submodules\n\nbut the new floating_submodules_draft branch adds Heiko's function\nreorganization and floating submodule pull (with 'update --branch') on\ntop of my v4 commits (instead of my branch-checkout with 'update\n--branch').\n\n> This looks fine, but my current --branch implementation (which doesn't\n> pull) is only a thin branch-checkout layer on top of the standard\n> `update` functionality.  I'm still unsure if built-in pulls are worth\n> the configuration trouble.  I'll sleep on it.  Maybe I'll feel better\n> about them tomorrow ;).\n\nI do feel better about them today.  To get a better feel for how\npeople see this going forward, here is a summary of proposals to date:\n\nv1. Record submodule.<name>.branch with 'submodule add --branch …',\n    leave interpretation up to the user.\n\n    Feedback (paraphrased):\n      Phil Hord: that clobbers a configure option used by Gerritt and\n        possibly others, rename to --record-branch.  Maybe we should\n        export submodule.<name>.* as $submodule_* in 'foreach'?\n      Nahor: what about corner cases (e.g. upstream renames branches)?\n      Jens Lehmann: if you record it, people will expect Git to use\n        it.  What about automatic pulls & commits?\n\nv2. Add --record instead of using --branch to address Phil's v1\n    comment.\n\n    Feedback (paraphrased):\n      Jens Lehmann: this is still a tiny optimization over using 'git\n        config'.  People still use this option in different ways.\n      Shawn Pearce: the Gerrit use is basically the same as Ævar's,\n        but Gerrit has special handling for '.'.\n      Jeff King: if we set up submodule.<name>.branch, we should\n        either use it in Git, or make it very clear that we do not use\n        it.  If we use Phil's $submodule_* export, we should clear the\n        variables for recursive submodules.\n\nv3. Renamed Added $submodule_* export to v2.  Give an example of\n    Ævar's pull workflow when explaining that Git does not use the\n    value internally.\n\n    Feedback (paraphrased):\n      Heiko Voigt: what about automatic pulls & commits?  You should\n        allow .git/config overrides of the .gitmodules settings.  if\n        we set up submodule.<name>.branch, we should use it in Git.\n        How does the submodule know which remote branch to track?\n        Junio's proposed 'diff' changes may hide $sha1 information.\n      Junio C Hamano: if we set up submodule.<name>.branch, we should\n        use it in Git.  Use something more specific than --record.\n        Update 'git diff [$path]' and friends in the superproject\n        compares the HEAD of the checkout of the submodule at $path\n        with the tip of the branch named by submodule.$name.branch in\n        .gitmodules of the superproject, instead of the commit that is\n        recorded in the index of the superproject.\n      Sascha Cunz: you can use 'git shortlog $OLD_SHA1..$NEW_SHA1' for\n        the automatic commit message.\n      Trevor King: actually, Ævar's update command only specifies the\n        local branch name.  The remote is recorded for that branch in\n        .git/modules/<name>/config.\n\nv4. Rename --record to --local-branch.  Remove $submodule_* export.\n    Add .git/config overrides for submodule.<name>.branch.  Add\n    'submodule update --branch' to check out $sha1 as\n    submodule.<name>.branch.\n\n    Feedback (paraphrased):\n      Heiko Voigt: who cares about the local branch name?  You should\n        be pulling origin/$branch, but still using\n        .git/modules/<name>/config to record the tracked branch.  You\n        should also use 'submodule add --branch[=branch]' instead of\n        '--local-branch'.  You should pull the 'update --branch'\n        functionality out into a sub-function like\n        'handle_tracked_branch_update'.\n      Jens Lehmann: .git/config overrides are nice, but they should be\n        optional.\n      Trevor King: floating branches are following the submodule's\n        remote, while 'update --rebase/--merge' are following the\n        superproject's recorded $sha1.  Bundling remote-following and\n        superproject-following in the same command may be confusing.\n\nHere's what I think we need in v5:\n\n* Jens' optional .git/config overrides.\n* Return --local-branch handling to a side effect of --branch (as in\n  v1).\n* A new 'submodule pull' for tracking the submodule's remote, which is\n  pulling --ff-only origin/$branch into a whatever state the submodule\n  is currently in.  If any changes were made to submodule $shas,\n  optionally commit them with a shortlog-generated commit message.\n* Remove my current 'submodule update --branch' functionality.\n\nThoughs?  Do we need any more information for an automatic pull, or is\n\n  $ git pull --ff-only origin/$branch\n\non a headless checkout sufficient?\n\nTrevor\n\n-- \nThis email may be signed or encrypted with GnuPG (http://www.gnupg.org).\nFor more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n"},{"id":"204166","messageId":"20121128165334.GA20483@odin.tremily.us","threadId":"32225","inReplyTo":"20121128130903.GB15786@odin.tremily.us","subject":"Re: [PATCH v4 0/4] git-submodule add: Add --local-branch option (summary)","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2012-11-28T16:53:34Z","receivedAt":"2012-11-28T16:53:34Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"On Wed, Nov 28, 2012 at 08:09:03AM -0500, W. Trevor King wrote:\n> * A new 'submodule pull' for tracking the submodule's remote, which is\n>   pulling --ff-only origin/$branch into a whatever state the submodule\n>   is currently in.  If any changes were made to submodule $shas,\n>   optionally commit them with a shortlog-generated commit message.\n\nI thought of a better idea on the train.  How about adding `--remote`\nto `submodule update` that overrides the gitlinked SHA-1 with the\nSHA-1 for origin/$branch?  All of the other checkout/merge/rebase\nfunctionality is untouched.  The only thing that changes is where we\nlook for the update.  I'm working up the patch now, and will submit v5\nshortly.\n\n-- \nThis email may be signed or encrypted with GnuPG (http://www.gnupg.org).\nFor more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n"},{"id":"204190","messageId":"cover.1354130656.git.wking@tremily.us","threadId":"32225","inReplyTo":"20121128165334.GA20483@odin.tremily.us","subject":"[PATCH v5 0/2] submodule update: add --remote for submodule's upstream changes","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2012-11-28T19:30:27Z","receivedAt":"2012-11-28T19:30:27Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"From: \"W. Trevor King\" <wking@tremily.us>\n\nOn Wed, Nov 28, 2012 at 11:53:34AM -0500, W. Trevor King wrote:\n> I thought of a better idea on the train.  How about adding `--remote`\n> to `submodule update` that overrides the gitlinked SHA-1 with the\n> SHA-1 for origin/$branch?  All of the other checkout/merge/rebase\n> functionality is untouched.  The only thing that changes is where we\n> look for the update.  I'm working up the patch now, and will submit v5\n> shortly.\n\nHere it is.\n\nChanges since v4:\n\n* Remove `update --branch` in favor of the new `update --remote` logic\n  as mentioned above.\n* Optional config overrides for submodule.<name>.branch (as suggested\n  by Jens)\n* Save --branch as submodule.<name>.branch instead of requiring\n  --local-branch.\n* Restructure doc edits.\n\nI'm a lot happier with this two-patch proposal.  The first patch\nimplements --remote and documents submodule.<name>.branch.  The second\npatch just gives you a convenient way to set it.  I haven't heard from\nanyone other than Heiko recently about the --branch/--remote-branch\nchoice, so I returned to the simpler --branch side effect storage from\nv1.  I'd be happy to submit v6 with explicit --remote-branch recording\nif desired.\n\nW. Trevor King (2):\n  submodule update: add --remote for submodule's upstream changes\n  submodule add: If --branch is given, record it in .gitmodules\n\n Documentation/config.txt        |  9 +++++----\n Documentation/git-submodule.txt | 26 +++++++++++++++++++++++++-\n Documentation/gitmodules.txt    |  5 +++++\n git-submodule.sh                | 30 +++++++++++++++++++++++++++++-\n t/t7400-submodule-basic.sh      |  1 +\n t/t7406-submodule-update.sh     | 31 +++++++++++++++++++++++++++++++\n 6 files changed, 96 insertions(+), 6 deletions(-)\n\n-- \n1.8.0.2.gad10246.dirty\n"},{"id":"204191","messageId":"36e431098b421a9d6d4dd372ca70b11cd7d59206.1354130656.git.wking@tremily.us","threadId":"32225","inReplyTo":"cover.1354130656.git.wking@tremily.us","subject":"[PATCH v5 1/2] submodule update: add --remote for submodule's upstream changes","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2012-11-28T19:30:28Z","receivedAt":"2012-11-28T19:30:28Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"From: \"W. Trevor King\" <wking@tremily.us>\n\nThe current `update` command incorporates the superproject's gitlinked\nSHA-1 ($sha1) into the submodule HEAD ($subsha1).  Depending on the\noptions you use, it may checkout $sha1, rebase the $subsha1 onto\n$sha1, or merge $sha1 into $subsha1.  This helps you keep up with\nchanges in the upstream superproject.\n\nHowever, it's also useful to stay up to date with changes in the\nupstream subproject.  Previous workflows for incorporating such\nchanges include the ungainly:\n\n  $ git submodule foreach 'git checkout $(git config --file $toplevel/.gitmodules submodule.$name.branch) && git pull'\n\nWith this patch, all of the useful functionality for incorporating\nsuperproject changes can be reused to incorporate upstream subproject\nupdates.  When you specify --remote, the target $sha1 is replaced with\na $sha1 of the submodule's origin/master tracking branch.  If you want\nto merge a different tracking branch, you can configure the\n`submodule.<name>.branch` option in `.gitmodules`.  You can override\nthe `.gitmodules` configuration setting for a particular superproject\nby configuring the option in that superproject's default configuration\n(using the usual configuration hierarchy, e.g. `.git/config`,\n`~/.gitconfig`, etc.).\n\nPrevious use of submodule.<name>.branch\n=======================================\n\nBecause we're adding a new configuration option, it's a good idea to\ncheck if anyone else is already using the option.  The foreach-pull\nexample above was described by Ævar in\n\n  commit f030c96d8643fa0a1a9b2bd9c2f36a77721fb61f\n  Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n  Date:   Fri May 21 16:10:10 2010 +0000\n\n    git-submodule foreach: Add $toplevel variable\n\nGerrit uses the same interpretation for the setting, but because\nGerrit has direct access to the subproject repositories, it updates\nthe superproject repositories automatically when a subproject changes.\nGerrit also accepts the special value '.', which it expands into the\nsuperproject's branch name.\n\nAlthough the --remote functionality is using `submodule.<name>.branch`\nslightly differently, the effect is the same.  The foreach-pull\nexample uses the option to record the name of the local branch to\ncheckout before pulls.  The tracking branch to be pulled is recorded\nin `.git/modules/<name>/config`, which was initialized by the module\nclone during `submodule add` or `submodule init`.  Because the branch\nname stored in `submodule.<name>.branch` was likely the same as the\nbranch name used during the initial `submodule add`, the same branch\nwill be pulled in each workflow.\n\nImplementation details\n======================\n\nIn order to ensure a current tracking branch state, `update --remote`\nfetches the submodule's remote repository before calculating the\nSHA-1.  However, I didn't change the logic guarding the existing fetch:\n\n  if test -z \"$nofetch\"\n  then\n    # Run fetch only if $sha1 isn't present or it\n    # is not reachable from a ref.\n    (clear_local_git_env; cd \"$path\" &&\n      ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&\n       test -z \"$rev\") || git-fetch)) ||\n    die \"$(eval_gettext \"Unable to fetch in submodule path '\\$path'\")\"\n  fi\n\nThere will not be a double-fetch, because the new $sha1 determined\nafter the `--remote` triggered fetch should always exist in the\nrepository.  If it doesn't, it's because some racy process removed it\nfrom the submodule's repository and we *should* be re-fetching.\n\nSigned-off-by: W. Trevor King <wking@tremily.us>\n---\n Documentation/config.txt        |  9 +++++----\n Documentation/git-submodule.txt | 24 +++++++++++++++++++++++-\n Documentation/gitmodules.txt    |  5 +++++\n git-submodule.sh                | 26 +++++++++++++++++++++++++-\n t/t7406-submodule-update.sh     | 31 +++++++++++++++++++++++++++++++\n 5 files changed, 89 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 11f320b..de39b1c 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1994,10 +1994,11 @@ status.submodulesummary::\n submodule.<name>.path::\n submodule.<name>.url::\n submodule.<name>.update::\n-\tThe path within this project, URL, and the updating strategy\n-\tfor a submodule.  These variables are initially populated\n-\tby 'git submodule init'; edit them to override the\n-\tURL and other values found in the `.gitmodules` file.  See\n+submodule.<name>.branch::\n+\tThe path within this project, URL, the updating strategy, and the\n+\tremote branch name for a submodule.  These variables are initially\n+\tpopulated by 'git submodule init'; edit them to override the URL and\n+\tother values found in the `.gitmodules` file.  See\n \tlinkgit:git-submodule[1] and linkgit:gitmodules[5] for details.\n \n submodule.<name>.fetchRecurseSubmodules::\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex b4683bb..39aa02d 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t      [--reference <repository>] [--] <repository> [<path>]\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n-'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]\n+'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] [--rebase]\n \t      [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n \t      [commit] [--] [<path>...]\n@@ -236,6 +236,28 @@ OPTIONS\n \t(the default). This limit only applies to modified submodules. The\n \tsize is always limited to 1 for added/deleted/typechanged submodules.\n \n+--remote::\n+\tThis option is only valid for the update command.\n+\tInstead of using the superproject's recorded SHA-1 to update the\n+\tsubmodule, use the status of the submodule's remote tracking branch.\n+\tThe remote tracking branch defaults to origin/master, but the branch\n+\tname may be overriden by setting the `submodule.<name>.branch`\n+\toption in either `.gitmodules` or `.git/config` (with `.git/config`\n+\ttaking precedence).\n++\n+This works for any of the supported update procedures (`--checkout`,\n+`--rebase`, etc.).  The only change is the source of the target SHA-1.\n+For example, `submodule update --remote --merge` will merge upstream\n+submodule changes into the submodules, while `submodule update\n+--merge` will merge superproject gitlink changes into the submodules.\n++\n+In order to ensure a current tracking branch state, `update --remote`\n+fetches the submodule's remote repository before calculating the\n+SHA-1.  This makes `submodule update --remote --merge` similar to\n+running `git pull` in the submodule.  If you don't want to fetch (for\n+something closer to `git merge`), you should use `submodule update\n+--remote --no-fetch --merge`.\n+\n -N::\n --no-fetch::\n \tThis option is only valid for the update command.\ndiff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt\nindex 4effd78..4004fa6 100644\n--- a/Documentation/gitmodules.txt\n+++ b/Documentation/gitmodules.txt\n@@ -47,6 +47,11 @@ submodule.<name>.update::\n \tThis config option is overridden if 'git submodule update' is given\n \tthe '--merge', '--rebase' or '--checkout' options.\n \n+submodule.<name>.branch::\n+\tA remote branch name for tracking updates in the upstream submodule.\n+\tIf the option is not specified, it defaults to 'master'.  See the\n+\t`--remote` documentation in linkgit:git-submodule[1] for details.\n+\n submodule.<name>.fetchRecurseSubmodules::\n \tThis option can be used to control recursive fetching of this\n \tsubmodule. If this option is also present in the submodules entry in\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ab6b110..b63d869 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -8,7 +8,8 @@ dashless=$(basename \"$0\" | sed -e 's/-/ /')\n USAGE=\"[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]\n    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] init [--] [<path>...]\n-   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n+   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n+ges\n    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]\n    or: $dashless [--quiet] foreach [--recursive] <command>\n    or: $dashless [--quiet] sync [--] [<path>...]\"\n@@ -26,6 +27,7 @@ cached=\n recursive=\n init=\n files=\n+remote=\n nofetch=\n update=\n prefix=\n@@ -509,6 +511,9 @@ cmd_update()\n \t\t-i|--init)\n \t\t\tinit=1\n \t\t\t;;\n+\t\t--remote)\n+\t\t\tremote=1\n+\t\t\t;;\n \t\t-N|--no-fetch)\n \t\t\tnofetch=1\n \t\t\t;;\n@@ -569,6 +574,12 @@ cmd_update()\n \t\tfi\n \t\tname=$(module_name \"$sm_path\") || exit\n \t\turl=$(git config submodule.\"$name\".url)\n+\t\tbranch=$(git config submodule.\"$name\".branch)\n+\t\tif test -z \"$branch\"\n+\t\tthen  # fall back on .gitmodules\n+\t\t\tbranch=$(git config -f .gitmodules submodule.\"$name\".branch)\n+\t\tfi\n+\t\tbranch=\"${branch:-master}\"\n \t\tif ! test -z \"$update\"\n \t\tthen\n \t\t\tupdate_module=$update\n@@ -603,6 +614,19 @@ Maybe you want to use 'update --init'?\")\"\n \t\t\tdie \"$(eval_gettext \"Unable to find current revision in submodule path '\\$sm_path'\")\"\n \t\tfi\n \n+\t\tif test -n \"$remote\"\n+\t\tthen\n+\t\t\tif test -z \"$nofetch\"\n+\t\t\tthen\n+\t\t\t\t# Fetch remote before determining tracking $sha1\n+\t\t\t\t(clear_local_git_env; cd \"$sm_path\" && git-fetch) ||\n+\t\t\t\tdie \"$(eval_gettext \"Unable to fetch in submodule path '\\$sm_path'\")\"\n+\t\t\tfi\n+\t\t\tsha1=$(clear_local_git_env; cd \"$sm_path\" &&\n+\t\t\t\tgit rev-parse --verify origin/\"$branch\") ||\n+\t\t\tdie \"$(eval_gettext \"Unable to find current origin/$branch revision in submodule path '\\$sm_path'\")\"\n+\t\tfi\n+\n \t\tif test \"$subsha1\" != \"$sha1\" -o -n \"$force\"\n \t\tthen\n \t\t\tsubforce=$force\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 1542653..a567834 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -135,6 +135,37 @@ test_expect_success 'submodule update --force forcibly checks out submodules' '\n \t)\n '\n \n+test_expect_success 'submodule update --remote should fetch upstream changes' '\n+\t(cd submodule &&\n+\t echo line4 >> file &&\n+\t git add file &&\n+\t test_tick &&\n+\t git commit -m \"upstream line4\"\n+\t) &&\n+\t(cd super &&\n+\t git submodule update --remote --force submodule &&\n+\t cd submodule &&\n+\t test \"$(git log -1 --oneline)\" = \"$(GIT_DIR=../../submodule/.git git log -1 --oneline)\"\n+\t)\n+'\n+\n+test_expect_success 'local config should override .gitmodules branch' '\n+\t(cd submodule &&\n+\t git checkout -b test-branch &&\n+\t echo line5 >> file &&\n+\t git add file &&\n+\t test_tick &&\n+\t git commit -m \"upstream line5\" &&\n+\t git checkout master\n+\t) &&\n+\t(cd super &&\n+\t git config submodule.submodule.branch test-branch &&\n+\t git submodule update --remote --force submodule &&\n+\t cd submodule &&\n+\t test \"$(git log -1 --oneline)\" = \"$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)\"\n+\t)\n+'\n+\n test_expect_success 'submodule update --rebase staying on master' '\n \t(cd super/submodule &&\n \t  git checkout master\n-- \n1.8.0.2.gad10246.dirty\n"},{"id":"204189","messageId":"572f6aee10162597c4544522330262e877e74992.1354130656.git.wking@tremily.us","threadId":"32225","inReplyTo":"cover.1354130656.git.wking@tremily.us","subject":"[PATCH v5 2/2] submodule add: If --branch is given, record it in .gitmodules","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2012-11-28T19:30:29Z","receivedAt":"2012-11-28T19:30:29Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"From: \"W. Trevor King\" <wking@tremily.us>\n\nThis allows you to easily record a submodule.<name>.branch option in\n.gitmodules when you add a new submodule.  With this patch,\n\n  $ git submodule add -b <branch> <repository> [<path>]\n  $ git config -f .gitmodules submodule.<path>.branch <branch>\n\nreduces to\n\n  $ git submodule add -b <branch> <repository> [<path>]\n\nThis means that future calls to\n\n  $ git submodule update --remote ...\n\nwill get updates from the same branch that you used to initialize the\nsubmodule, which is usually what you want.\n\nSigned-off-by: W. Trevor King <wking@tremily.us>\n---\n Documentation/git-submodule.txt | 2 ++\n git-submodule.sh                | 4 ++++\n t/t7400-submodule-basic.sh      | 1 +\n 3 files changed, 7 insertions(+)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 39aa02d..43e5b4b 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -208,6 +208,8 @@ OPTIONS\n -b::\n --branch::\n \tBranch of repository to add as submodule.\n+\tThe name of the branch is recorded as `submodule.<path>.branch` in\n+\t`.gitmodules` for `update --remote`.\n \n -f::\n --force::\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex b63d869..1f76893 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -368,6 +368,10 @@ Use -f if you really want to add it.\" >&2\n \n \tgit config -f .gitmodules submodule.\"$sm_path\".path \"$sm_path\" &&\n \tgit config -f .gitmodules submodule.\"$sm_path\".url \"$repo\" &&\n+\tif test -n \"$branch\"\n+\tthen\n+\t\tgit config -f .gitmodules submodule.\"$sm_path\".branch \"$branch\"\n+\tfi &&\n \tgit add --force .gitmodules ||\n \tdie \"$(eval_gettext \"Failed to register submodule '\\$sm_path'\")\"\n }\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 5397037..90e2915 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -133,6 +133,7 @@ test_expect_success 'submodule add --branch' '\n \t(\n \t\tcd addtest &&\n \t\tgit submodule add -b initial \"$submodurl\" submod-branch &&\n+\t\ttest \"initial\" = \"$(git config -f .gitmodules submodule.submod-branch.branch)\" &&\n \t\tgit submodule init\n \t) &&\n \n-- \n1.8.0.2.gad10246.dirty\n"}]}