checkout: disambiguate dwim tracking branches and local files

When checkout dwim is added in [1], it is restricted to only dwim when
certain conditions are met and fall back to default checkout behavior
otherwise. It turns out falling back could be confusing. One of the
conditions to turn

    git checkout frotz

to

    git checkout -b frotz origin/frotz

is that frotz must not exist as a file. But when the user comes to
expect "git checkout frotz" to create the branch "frotz" and there
happens to be a file named "frotz", git's silently reverting "frotz"
file content is not helping. This is reported in Git mailing list [2]
and even used as an example of "Git is bad" elsewhere [3].

We normally try to do the right thing, but when there are multiple
"right things" to do, it's best to leave it to the user to decide.
Check this case, ask the user to to disambiguate:

- "git checkout -- foo" will check out path "foo"
- "git checkout foo --" will dwim and create branch "foo" [4]

For users who do not want dwim, use --no-guess. It's useless in this
particular case because "git checkout --no-guess foo --" will just
fail. But it could be used by scripts.

[1] 70c9ac2f19 (DWIM "git checkout frotz" to "git checkout -b frotz
    origin/frotz" - 2009-10-18)
[2] https://public-inbox.org/git/CACsJy8B2TVr1g+k+eSQ=pBEO3WN4_LtgLo9gpur8X7Z9GOFL_A@mail.gmail.com/
[3] https://news.ycombinator.com/item?id=18230655
[4] a047fafc78 (checkout: allow dwim for branch creation for "git
    checkout $branch --" - 2013-10-18)

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

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