2

I already read this question: Modified files in a git branch are spilling over into another branch and I understand (I hope) how git works.

Could you explain me why it works like that, I do not understand the mindset. I only found disadvantages but no advantage...

1 Answer 1

2

The idea is to not change a file being modified without the explicit user's authorization: that is the "mindset": no unwanted "surprise".

Changing branch doesn't change by default modified files.
It actually blocks the checkout if those modified files would be overwritten during said checkout: it is up to the user to decide if those changes stay or go.

"In practical": you don't want a tool do do anything "for you". You want to use the tool the way you intent.

If you intent to clean untracked files:

The tool alone cannot decide what should be done with those untracked/modified files when switching branch.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok for the idea, it looks great, but in practical: I'am working on master, and I already modified some files, when I think to do a refactoring. So, I create a new branch refacto and work on it. I remove some files I previously created on master but not yet committed. The refactoring was finally not a good idea and I decide to 'revert' to master and delete the refacto branch. But in master branch uncommitted files where delete from the 'refacto' branch'. How can I do to avoid this problem? Even if I well understand the idea, I don't understand why git works like this and what are the benefits?
@Calfater "in practical": you don't want a tool do do anything "for you". You want to use the tool the way you intent. If you intent to clean untracked files, clean the worktree: stackoverflow.com/a/64966/6309, or reset it with (stackoverflow.com/a/19032417/6309) git checkout -- . (or stash it stackoverflow.com/a/20609889/6309 if you want to reuse that work in progress later)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.