How to force Git to abort a checkout if working directory is not clean (i.e. disregarding the check for conflicts)? -


when git checkout some_branch, , working directory not clean, git check if checkout result in conflicts, , if abort with:

$ git checkout some_branch error: local changes following files overwritten checkout:         some_file please, commit changes or stash them before can switch branches. aborting 

however, if checkout not result in conflicts, git switch new branch , carry on uncommitted changes (and listing them, polite git is).

$ git checkout some_branch m       some_file m       some_other_file switched branch 'some_branch' 

so far ...

now, not git users uses cmd line. if use ide (like e.g. eclipse) , checkout of some_branch dirty working directory not result in conflicts, not nicely notified changes working on in previous_branch still present in working directory after changing some_branch.

i.e. when compile code uncommitted changes previous_branch still present in working directory on some_branch.

question #1:

is possible force git abort checkout if working directory not clean (no matter if there conflicts or not)?

i prefer setting in global git config.

question #2:

if not possible setup, valid request new config option in git?

as see git strong in context switching (i.e. working on multiple issues on multiple branches), , see use setting setup strict check if working directory not clean (disregarding check conflicts).

this mean changes created while on branch #1 not carried on when changing branch #2, i.e. work strictly context based always.

any views or opinions on this?

i'm not aware of such option, here's script simulate behavior. maybe ide(or os) can configured run script instead of git-checkout.

#!/bin/sh  modified=$(git status -s | grep ^\ m)  if [ "$modified" != "" ];   echo "current branch dirty!"   exit 1 else   git checkout $1 fi 

you can name script git-cleancheckout, put $path , run this

git cleancheckout mybranch 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -