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

Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)

From
JBJonas Bang <email@jonasbang.dk>
Date
Mar 27, 2014, 16:15 UTC
Message-ID
<004d01cf49d7$c8b9cd90$5a2d68b0$@jonasbang.dk>
Hi Git developers, 

This is my first Git feature request, I hope it won’t get me hanged on the gallows ;o)

*Git feature request:* Add an option to Git config to configure the criteria for when a "git checkout" should abort.

*Name proposal and options:* checkout.clean false <default> checkout.clean true

*False behavior:* As is: When doing a checkout then Git will check if your working directory is dirty, and if so check if the checkout will result in any conflicts, and if so abort the checkout with a message:

$ git checkout some_branch
error: Your local changes to the following files would be overwritten by
checkout:
       some_file
Please, commit your changes or stash them before you can switch branches.
Aborting 
If no conflicts then: 

$ git checkout some_branch M       some_file M       some_other_file Switched to branch 'some_branch'

I.e. it will only abort if there are conflicts. 

*True behavior:* When doing a checkout then Git will check if your working directory is dirty (checking for both modified and added untracked files), and if so abort the checkout with a message:

$ git checkout some_branch error: Your working directory is not clean. Please, commit your changes or stash them before you can switch branches. Aborting

I.e. it will abort if working directory is dirty (checking for both modified and added untracked files). I.e. you can only do checkout if you get "nothing to commit, working directory clean" when running "git status" (ignoring ignored files though).

*Usecase in short:* If you use an IDE (like e.g. Eclipse) and do a checkout of 'some_branch' with a dirty working directory which will not result in any conflicts, then you will not be nicely notified (as you would in Git Bash) that the changes you were working on in 'previous_branch' are still present in your working directory after changing to 'some_branch'. I.e. when you compile your code your uncommitted changes from 'previous_branch' are still present in your working directory on 'some_branch'.

As I see it Git is extremely strong in context switching (i.e. working on multiple issues on multiple branches), and I could see a use for a setting which setup a strict check for if working directory is not clean (disregarding the check for conflicts). This would mean that your changes created while on branch #1 will not be carried over when changing to branch #2, i.e. you will work strictly context based always.

*Usecase also described here:* http://stackoverflow.com/questions/22609566/how-to-force-git-to-abort-a-chec kout-if-working-directory-is-not-clean-i-e-dis

Br, Jonas Bang Christensen

Next: Junio C Hamano
Message 1 of 7 in “Git feature request: Option to force Git to abort a checkout if working directory is dirty (i.e. disregarding the check for conflicts)”
  1. Jonas BangMar 27, 2014
  2. Junio C HamanoMar 27, 2014
  3. Jonas BangMar 29, 2014
  4. Junio C HamanoMar 31, 2014
  5. Jonas BangApr 1, 2014
  6. Junio C HamanoApr 2, 2014
  7. Jonas BangApr 3, 2014

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.