checkout: add simple check for 'git checkout -b'

The 'git switch' command was created to separate half of the
behavior of 'git checkout'. It specifically has the mode to
do nothing with the index and working directory if the user
only specifies to create a new branch and change HEAD to that
branch. This is also the behavior most users expect from
'git checkout -b', but for historical reasons it also performs
an index update by scanning the working directory. This can be
slow for even moderately-sized repos.

A performance fix for 'git checkout -b' was introduced by
fa655d8411 (checkout: optimize "git checkout -b <new_branch>"
2018-08-16). That change includes details about the config
setting checkout.optimizeNewBranch when the sparse-checkout
feature is required. The way this change detected if this
behavior change is safe was through the skip_merge_working_tree()
method. This method was complex and needed to be updated
as new options were introduced.

This behavior was essentially reverted by 65f099b ("switch:
no worktree status unless real branch switch happens"
2019-03-29). Instead, two members of the checkout_opts struct
were used to distinguish between 'git checkout' and 'git switch':

    * switch_branch_doing_nothing_is_ok
    * only_merge_on_switching_branches

These settings have opposite values depending on if we start
in cmd_checkout or cmd_switch.

The message for 64f099b includes "Users of big repos are
encouraged to move to switch." Making this change while
'git switch' is still experimental is too aggressive.

Create a happy medium between these two options by making
'git checkout -b <branch>' behave just like 'git switch',
but only if we read exactly those arguments. This must
be done in cmd_checkout to avoid the arguments being
consumed by the option parsing logic.

This differs from the previous change by fa644d8 in that
the config option checkout.optimizeNewBranch remains
deleted. This means that 'git checkout -b' will ignore
the index merge even if we have a sparse-checkout file.
While this is a behavior change for 'git checkout -b',
it matches the behavior of 'git switch -c'.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Acked-by: Elijah Newren <newren@gmail.com>
Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: bbbeab9a996876723693828423b8c19b8ce40923
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. negotiator/
  14. perl/
  15. po/
  16. ppc/
  17. refs/
  18. sha1dc/
  19. sha256/
  20. t/
  21. templates/
  22. trace2/
  23. vcs-svn/
  24. xdiff/
  25. .clang-format
  26. .editorconfig
  27. .gitattributes
  28. .gitignore
  29. .gitmodules
  30. .mailmap
  31. .travis.yml
  32. .tsan-suppressions
  33. abspath.c
  34. aclocal.m4
  35. advice.c
  36. advice.h
  37. alias.c
  38. alias.h
  39. alloc.c
  40. alloc.h
  41. apply.c
  42. apply.h
  43. archive-tar.c
  44. archive-zip.c
  45. archive.c
  46. archive.h
  47. argv-array.c
  48. argv-array.h
  49. attr.c
  50. attr.h
  51. azure-pipelines.yml
  52. banned.h
  53. base85.c
  54. bisect.c
  55. bisect.h
  56. blame.c
  57. blame.h
  58. blob.c
  59. blob.h
  60. branch.c
  61. branch.h
  62. builtin.h
  63. bulk-checkin.c
  64. bulk-checkin.h
  65. bundle.c
  66. bundle.h
  67. cache-tree.c
  68. cache-tree.h
  69. cache.h
  70. chdir-notify.c
  71. chdir-notify.h
  72. check-builtins.sh
  73. check_bindir
  74. checkout.c
  75. checkout.h
  76. color.c
  77. color.h
  78. column.c
  79. column.h
  80. combine-diff.c
  81. command-list.txt
  82. commit-graph.c
  83. commit-graph.h
  84. commit-reach.c
  85. commit-reach.h
  86. commit-slab-decl.h
  87. commit-slab-impl.h
  88. commit-slab.h
  89. commit.c
  90. commit.h
  91. common-main.c
  92. config.c
  93. config.h
  94. config.mak.dev
  95. config.mak.in
  96. config.mak.uname
  97. configure.ac
  98. connect.c
  99. connect.h
  100. connected.c
  101. connected.h
  102. convert.c
  103. convert.h
  104. copy.c
  105. COPYING
  106. credential-cache--daemon.c
  107. credential-cache.c
  108. credential-store.c
  109. credential.c
  110. credential.h
  111. csum-file.c
  112. csum-file.h
  113. ctype.c
  114. daemon.c
  115. date.c
  116. decorate.c
  117. decorate.h
  118. delta-islands.c
  119. delta-islands.h
  120. delta.h
  121. detect-compiler
  122. diff-delta.c
  123. diff-lib.c
  124. diff-no-index.c
  125. diff.c
  126. diff.h
  127. diffcore-break.c
  128. diffcore-delta.c
  129. diffcore-order.c
  130. diffcore-pickaxe.c
  131. diffcore-rename.c
  132. diffcore.h
  133. dir-iterator.c
  134. dir-iterator.h
  135. dir.c
  136. dir.h
  137. editor.c
  138. entry.c
  139. environment.c
  140. exec-cmd.c
  141. exec-cmd.h
  142. fast-import.c
  143. fetch-negotiator.c
  144. fetch-negotiator.h
  145. fetch-object.c
  146. fetch-object.h
  147. fetch-pack.c
  148. fetch-pack.h
  149. fmt-merge-msg.h
  150. fsck.c
  151. fsck.h
  152. fsmonitor.c
  153. fsmonitor.h
  154. fuzz-commit-graph.c
  155. fuzz-pack-headers.c
  156. fuzz-pack-idx.c
  157. generate-cmdlist.sh
  158. gettext.c
  159. gettext.h
  160. git-add--interactive.perl
  161. git-archimport.perl
  162. git-bisect.sh
  163. git-compat-util.h
  164. git-cvsexportcommit.perl
  165. git-cvsimport.perl
  166. git-cvsserver.perl
  167. git-difftool--helper.sh
  168. git-filter-branch.sh
  169. git-instaweb.sh
  170. git-legacy-rebase.sh
  171. git-merge-octopus.sh
  172. git-merge-one-file.sh
  173. git-merge-resolve.sh
  174. git-mergetool--lib.sh
  175. git-mergetool.sh
  176. git-p4.py
  177. git-parse-remote.sh
  178. git-quiltimport.sh
  179. git-rebase--am.sh
  180. git-rebase--common.sh
  181. git-rebase--preserve-merges.sh
  182. git-remote-testgit.sh
  183. git-request-pull.sh
  184. git-send-email.perl
  185. git-sh-i18n.sh
  186. git-sh-setup.sh
  187. git-stash.sh
  188. git-submodule.sh
  189. git-svn.perl
  190. GIT-VERSION-GEN
  191. git-web--browse.sh
  192. git.c
  193. git.rc
  194. gpg-interface.c
  195. gpg-interface.h
  196. graph.c
  197. graph.h
  198. grep.c
  199. grep.h
  200. hash.h
  201. hashmap.c
  202. hashmap.h
  203. help.c
  204. help.h
  205. hex.c
  206. http-backend.c
  207. http-fetch.c
  208. http-push.c
  209. http-walker.c
  210. http.c
  211. http.h
  212. ident.c
  213. imap-send.c
  214. INSTALL
  215. interdiff.c
  216. interdiff.h
  217. iterator.h
  218. json-writer.c
  219. json-writer.h
  220. khash.h
  221. kwset.c
  222. kwset.h
  223. levenshtein.c
  224. levenshtein.h
  225. LGPL-2.1
  226. line-log.c
  227. line-log.h
  228. line-range.c
  229. line-range.h
  230. linear-assignment.c
  231. linear-assignment.h
  232. list-objects-filter-options.c
  233. list-objects-filter-options.h
  234. list-objects-filter.c
  235. list-objects-filter.h
  236. list-objects.c
  237. list-objects.h
  238. list.h
  239. ll-merge.c
  240. ll-merge.h
  241. lockfile.c
  242. lockfile.h
  243. log-tree.c
  244. log-tree.h
  245. ls-refs.c
  246. ls-refs.h
  247. mailinfo.c
  248. mailinfo.h
  249. mailmap.c
  250. mailmap.h
  251. Makefile
  252. match-trees.c
  253. mem-pool.c
  254. mem-pool.h
  255. merge-blobs.c
  256. merge-blobs.h
  257. merge-recursive.c
  258. merge-recursive.h
  259. merge.c
  260. mergesort.c
  261. mergesort.h
  262. midx.c
  263. midx.h
  264. name-hash.c
  265. notes-cache.c
  266. notes-cache.h
  267. notes-merge.c
  268. notes-merge.h
  269. notes-utils.c
  270. notes-utils.h
  271. notes.c
  272. notes.h
  273. object-store.h
  274. object.c
  275. object.h
  276. oidmap.c
  277. oidmap.h
  278. oidset.c
  279. oidset.h
  280. pack-bitmap-write.c
  281. pack-bitmap.c
  282. pack-bitmap.h
  283. pack-check.c
  284. pack-objects.c
  285. pack-objects.h
  286. pack-revindex.c
  287. pack-revindex.h
  288. pack-write.c
  289. pack.h
  290. packfile.c
  291. packfile.h
  292. pager.c
  293. parse-options-cb.c
  294. parse-options.c
  295. parse-options.h
  296. patch-delta.c
  297. patch-ids.c
  298. patch-ids.h
  299. path.c
  300. path.h
  301. pathspec.c
  302. pathspec.h
  303. pkt-line.c
  304. pkt-line.h
  305. preload-index.c
  306. pretty.c
  307. pretty.h
  308. prio-queue.c
  309. prio-queue.h
  310. progress.c
  311. progress.h
  312. prompt.c
  313. prompt.h
  314. protocol.c
  315. protocol.h
  316. quote.c
  317. quote.h
  318. range-diff.c
  319. range-diff.h
  320. reachable.c
  321. reachable.h
  322. read-cache.c
  323. README.md
  324. rebase-interactive.c
  325. rebase-interactive.h
  326. ref-filter.c
  327. ref-filter.h
  328. reflog-walk.c
  329. reflog-walk.h
  330. refs.c
  331. refs.h
  332. refspec.c
  333. refspec.h
  334. remote-curl.c
  335. remote-testsvn.c
  336. remote.c
  337. remote.h
  338. replace-object.c
  339. replace-object.h
  340. repository.c
  341. repository.h
  342. rerere.c
  343. rerere.h
  344. resolve-undo.c
  345. resolve-undo.h
  346. revision.c
  347. revision.h
  348. run-command.c
  349. run-command.h
  350. send-pack.c
  351. send-pack.h
  352. sequencer.c
  353. sequencer.h
  354. serve.c
  355. serve.h
  356. server-info.c
  357. setup.c
  358. sh-i18n--envsubst.c
  359. sha1-array.c
  360. sha1-array.h
  361. sha1-file.c
  362. sha1-lookup.c
  363. sha1-lookup.h
  364. sha1-name.c
  365. sha1dc_git.c
  366. sha1dc_git.h
  367. shallow.c
  368. shell.c
  369. shortlog.h
  370. sideband.c
  371. sideband.h
  372. sigchain.c
  373. sigchain.h
  374. split-index.c
  375. split-index.h
  376. strbuf.c
  377. strbuf.h
  378. streaming.c
  379. streaming.h
  380. string-list.c
  381. string-list.h
  382. sub-process.c
  383. sub-process.h
  384. submodule-config.c
  385. submodule-config.h
  386. submodule.c
  387. submodule.h
  388. symlinks.c
  389. tag.c
  390. tag.h
  391. tar.h
  392. tempfile.c
  393. tempfile.h
  394. thread-utils.c
  395. thread-utils.h
  396. tmp-objdir.c
  397. tmp-objdir.h
  398. trace.c
  399. trace.h
  400. trace2.c
  401. trace2.h
  402. trailer.c
  403. trailer.h
  404. transport-helper.c
  405. transport-internal.h
  406. transport.c
  407. transport.h
  408. tree-diff.c
  409. tree-walk.c
  410. tree-walk.h
  411. tree.c
  412. tree.h
  413. unicode-width.h
  414. unimplemented.sh
  415. unix-socket.c
  416. unix-socket.h
  417. unpack-trees.c
  418. unpack-trees.h
  419. upload-pack.c
  420. upload-pack.h
  421. url.c
  422. url.h
  423. urlmatch.c
  424. urlmatch.h
  425. usage.c
  426. userdiff.c
  427. userdiff.h
  428. utf8.c
  429. utf8.h
  430. varint.c
  431. varint.h
  432. version.c
  433. version.h
  434. versioncmp.c
  435. walker.c
  436. walker.h
  437. wildmatch.c
  438. wildmatch.h
  439. worktree.c
  440. worktree.h
  441. wrap-for-bin.sh
  442. wrapper.c
  443. write-or-die.c
  444. ws.c
  445. wt-status.c
  446. wt-status.h
  447. xdiff-interface.c
  448. xdiff-interface.h
  449. zlib.c
README.md

Build Status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission). To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org. The mailing list archives are available at https://public-inbox.org/git/, http://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks