git/Documentation/config
Tao Klerks bdaf1dfae7 branch: new autosetupmerge option 'simple' for matching branches
With the default push.default option, "simple", beginners are
protected from accidentally pushing to the "wrong" branch in
centralized workflows: if the remote tracking branch they would push
to does not have the same name as the local branch, and they try to do
a "default push", they get an error and explanation with options.

There is a particular centralized workflow where this often happens:
a user branches to a new local topic branch from an existing
remote branch, eg with "checkout -b feature1 origin/master". With
the default branch.autosetupmerge configuration (value "true"), git
will automatically add origin/master as the upstream tracking branch.

When the user pushes with a default "git push", with the intention of
pushing their (new) topic branch to the remote, they get an error, and
(amongst other things) a suggestion to run "git push origin HEAD".

If they follow this suggestion the push succeeds, but on subsequent
default pushes they continue to get an error - so eventually they
figure out to add "-u" to change the tracking branch, or they spelunk
the push.default config doc as proposed and set it to "current", or
some GUI tooling does one or the other of these things for them.

When one of their coworkers later works on the same topic branch,
they don't get any of that "weirdness". They just "git checkout
feature1" and everything works exactly as they expect, with the shared
remote branch set up as remote tracking branch, and push and pull
working out of the box.

The "stable state" for this way of working is that local branches have
the same-name remote tracking branch (origin/feature1 in this
example), and multiple people can work on that remote feature branch
at the same time, trusting "git pull" to merge or rebase as required
for them to be able to push their interim changes to that same feature
branch on that same remote.

(merging from the upstream "master" branch, and merging back to it,
are separate more involved processes in this flow).

There is a problem in this flow/way of working, however, which is that
the first user, when they first branched from origin/master, ended up
with the "wrong" remote tracking branch (different from the stable
state). For a while, before they pushed (and maybe longer, if they
don't use -u/--set-upstream), their "git pull" wasn't getting other
users' changes to the feature branch - it was getting any changes from
the remote "master" branch instead (a completely different class of
changes!)

An experienced git user might say "well yeah, that's what it means to
have the remote tracking branch set to origin/master!" - but the
original user above didn't *ask* to have the remote master branch
added as remote tracking branch - that just happened automatically
when they branched their feature branch. They didn't necessarily even
notice or understand the meaning of the "set up to track 'origin/master'"
message when they created the branch - especially if they are using a
GUI.

Looking at how to fix this, you might think "OK, so disable auto setup
of remote tracking - set branch.autosetupmerge to false" - but that
will inconvenience the *second* user in this story - the one who just
wanted to start working on the topic branch. The first and second
users swap roles at different points in time of course - they should
both have a sane configuration that does the right thing in both
situations.

Make this "branches have the same name locally as on the remote"
workflow less painful / more obvious by introducing a new
branch.autosetupmerge option called "simple", to match the same-name
"push.default" option that makes similar assumptions.

This new option automatically sets up tracking in a *subset* of the
current default situations: when the original ref is a remote tracking
branch *and* has the same branch name on the remote (as the new local
branch name).

Update the error displayed when the 'push.default=simple' configuration
rejects a mismatching-upstream-name default push, to offer this new
branch.autosetupmerge option that will prevent this class of error.

With this new configuration, in the example situation above, the first
user does *not* get origin/master set up as the tracking branch for
the new local branch. If they "git pull" in their new local-only
branch, they get an error explaining there is no upstream branch -
which makes sense and is helpful. If they "git push", they get an
error explaining how to push *and* suggesting they specify
--set-upstream - which is exactly the right thing to do for them.

This new option is likely not appropriate for users intentionally
implementing a "triangular workflow" with a shared upstream tracking
branch, that they "git pull" in and a "private" feature branch that
they push/force-push to just for remote safe-keeping until they are
ready to push up to the shared branch explicitly/separately. Such
users are likely to prefer keeping the current default
merge.autosetupmerge=true behavior, and change their push.default to
"current".

Also extend the existing branch tests with three new cases testing
this option - the obvious matching-name and non-matching-name cases,
and also a non-matching-ref-type case. The matching-name case needs to
temporarily create an independent repo to fetch from, as the general
strategy of using the local repo as the remote in these tests
precludes locally branching with the same name as in the "remote".

Signed-off-by: Tao Klerks <tao@klerks.biz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-04-29 11:20:55 -07:00
..
add.txt Start to implement a built-in version of git add --interactive 2019-11-14 11:10:04 +09:00
advice.txt Merge branch 'tk/ambiguous-fetch-refspec' 2022-04-04 10:56:24 -07:00
alias.txt config/alias.txt: document alias accepting non-command first word 2019-06-06 09:33:42 -07:00
am.txt
apply.txt
blame.txt blame: correct name of config option in docs 2021-06-28 10:05:13 -07:00
branch.txt branch: new autosetupmerge option 'simple' for matching branches 2022-04-29 11:20:55 -07:00
browser.txt
checkout.txt parallel-checkout: add configuration options 2021-04-19 11:57:05 -07:00
clean.txt
clone.txt clone, submodule: pass partial clone filters to submodules 2022-02-09 15:38:36 -08:00
color.txt Merge branch 'hm/paint-hits-in-log-grep' 2021-11-01 13:48:08 -07:00
column.txt
commit.txt
commitgraph.txt commit-graph: use config to specify generation type 2021-02-25 15:10:41 -08:00
completion.txt
core.txt doc: replace "--" with {litdd} in credential-cache/fsmonitor 2022-04-06 16:06:06 -07:00
credential.txt crendential-store: use timeout when locking file 2020-11-25 12:30:18 -08:00
diff.txt rename: bump limit defaults yet again 2021-07-15 16:54:34 -07:00
difftool.txt
extensions.txt Documentation: add extensions.worktreeConfig details 2022-02-08 09:49:20 -08:00
fastimport.txt
feature.txt protocol: re-enable v2 protocol by default 2020-09-25 11:40:42 -07:00
fetch.txt repo-settings: rename the traditional default fetch.negotiationAlgorithm 2022-02-02 09:36:17 -08:00
filter.txt
fmt-merge-msg.txt config/fmt-merge-msg.txt: drop space in quote 2020-09-27 14:22:41 -07:00
format.txt Merge branch 'jc/format-patch-name-max' 2020-11-21 15:14:38 -08:00
fsck.txt config/fsck.txt: avoid starting line with dash 2019-03-07 09:25:32 +09:00
gc.txt gc docs: change --keep-base-pack to --keep-largest-pack 2020-11-21 11:39:55 -08:00
gitcvs.txt
gitweb.txt
gpg.txt Documentation/config/pgp.txt: add missing apostrophe 2022-01-26 18:31:59 -08:00
grep.txt grep: clarify what grep.patternType=default means 2021-12-05 12:26:43 -08:00
gui.txt docs: use "character encoding" to refer to commit-object encoding 2021-08-27 12:45:45 -07:00
guitool.txt
help.txt help.c: help.autocorrect=prompt waits for user action 2021-08-14 11:20:49 -07:00
http.txt doc: fix some typos 2021-01-04 11:27:48 -08:00
i18n.txt
imap.txt
index.txt sparse-index: add index.sparse config option 2021-03-30 12:57:47 -07:00
init.txt clone: respect remote unborn HEAD 2021-02-05 13:49:55 -08:00
instaweb.txt
interactive.txt checkout: split part of it to new command 'restore' 2019-05-07 13:04:47 +09:00
log.txt diff-merges: introduce log.diffMerges config variable 2021-04-16 23:38:35 -07:00
lsrefs.txt ls-refs: report unborn targets of symrefs 2021-02-05 13:49:53 -08:00
mailinfo.txt
mailmap.txt
maintenance.txt maintenance: incremental strategy runs pack-refs weekly 2021-02-09 23:09:29 -08:00
man.txt
merge.txt update documentation for new zdiff3 conflictStyle 2021-12-01 14:45:59 -08:00
mergetool.txt mergetool: do not enable hideResolved by default 2021-03-13 15:30:29 -08:00
notes.txt
pack.txt midx.c: respect 'pack.writeBitmapHashcache' when writing bitmaps 2021-09-14 16:34:18 -07:00
pager.txt
pretty.txt
protocol.txt protocol: re-enable v2 protocol by default 2020-09-25 11:40:42 -07:00
pull.txt pull: remove support for --rebase=preserve 2021-09-07 21:45:32 -07:00
push.txt Merge branch 'fc/push-simple-updates' 2021-07-13 16:52:49 -07:00
rebase.txt rebase: remove transitory rebase.useBuiltin setting & env 2021-03-23 14:05:58 -07:00
receive.txt receive-pack: new config receive.procReceiveRefs 2020-08-27 12:47:47 -07:00
remote.txt docs: mention --refetch fetch option 2022-03-28 10:25:53 -07:00
remotes.txt
repack.txt repack: add config to skip updating server info 2022-03-14 22:25:13 +00:00
rerere.txt
safe.txt setup: opt-out of check with safe.directory=* 2022-04-13 12:42:51 -07:00
sendemail.txt send-email: remove non-working support for "sendemail.smtpssl" 2021-05-28 18:38:07 +09:00
sequencer.txt
showbranch.txt
sparse.txt repo_read_index: add config to expect files outside sparse patterns 2022-03-01 23:37:48 -08:00
splitindex.txt
ssh.txt
stash.txt stash: remove documentation for stash.useBuiltin 2022-01-27 18:00:37 -08:00
status.txt status: add status.aheadbehind setting 2019-06-21 09:35:00 -07:00
submodule.txt branch: add --recurse-submodules option for branch creation 2022-02-04 08:16:39 -08:00
tag.txt separate tar.* config to its own source file 2020-03-18 12:42:09 -07:00
tar.txt separate tar.* config to its own source file 2020-03-18 12:42:09 -07:00
trace2.txt doc: fix some typos 2021-01-04 11:27:48 -08:00
transfer.txt docs: clarify the interaction of transfer.hideRefs and namespaces 2021-09-01 07:54:30 -07:00
uploadarchive.txt
uploadpack.txt list-objects: implement object type filter 2021-04-19 14:09:11 -07:00
url.txt
user.txt ssh signing: support non ssh-* keytypes 2021-11-19 09:05:25 -08:00
versionsort.txt
web.txt
worktree.txt