git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git switch --force vs --discard-changes: docs don't match behavior

From
David Mandelberg <david@mandelberg.org>
Date
Mar 17, 2025, 16:50 UTC
Message-ID
<bce5a500-76c4-4462-8f99-b17a6f21f7ec@mandelberg.org>
Hi,

https://github.com/git/git/blob/683c54c999c301c2cd6f715c411407c413b1d84e/Documentation/git-switch.adoc?plain=1#L115-L124 describes --force as "An alias for `--discard-changes`."

At least on git 2.47.2 though[1], it looks like --force will force more things than --discard-changes:

$ touch Makefile
$ git switch master
error: The following untracked working tree files would be overwritten 
by checkout:
         Makefile
Please move or remove them before you switch branches.
Aborting
$ git switch --discard-changes master
error: Untracked working tree file 'Makefile' would be overwritten by merge.
$ git switch --force master
branch 'master' set up to track 'origin/master'.
Switched to a new branch 'master'
Is this a bug in the code or documentation?

[1] I searched the mailing list to see if there were any relevant changes since then.

Next: Junio C Hamano
Message 1 of 4 in “git switch --force vs --discard-changes: docs don't match behavior”
  1. David MandelbergMar 17, 2025
  2. Junio C HamanoMar 17, 2025
  3. Junio C HamanoMar 17, 2025
  4. David MandelbergMar 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.