Say I have a git repo whose working tree and/or index is "dirty" (i.e. I have local modifications that have not yet been committed or stashed) and I'm tempted to do a "git pull" without first committing or stashing. (Alternatively, say I'm introducing a new team member to git and they are tempted to run "git pull" when their local repo is "dirty".) I'm wondering how safe it is to do a "git pull" in this case. If it's unsafe, what's the worst thing that can happen? Does it matter if I'm pulling from a trusted vs untrusted source?
My investigation so far suggests a confusing range of ideas on what I'd assumed would be a fairly straightforward question.
To start with, the git-stash manpage makes it sound like git pull is pretty safe, and will abort if you're in a situation where something might go wrong:
Pulling into a dirty tree
When you are in the middle of something, you learn that there are
upstream changes that are possibly relevant to what you are doing.
When your local changes do not conflict with the changes in the
upstream, a simple git pull will let you move forward.
However, there are cases in which your local changes do conflict
with the upstream changes, and git pull refuses to overwrite your
changes. In such a case, you can stash your changes away, perform a
pull, and then unstash, like this...
This actually seems to be what happens too, in my simple tests so far.
Also perhaps implying that "git pull" is pretty safe, the Git Extensions toolbar for Visual Studio has a prominent pull button that does not do a check for dirtiness before shelling out to "git pull". (If I were designing a Visual Studio toolbar, I would try to avoid making it particularly easy to shoot yourself in the foot.)
The git-pull manpage doesn't make my "git pull" sound dangerous, though it suggests it's not a best practice:
If any of the remote changes overlap with local uncommitted changes,
the merge will be automatically cancelled and the work tree untouched.
It is generally best to get any local changes in working order before
pulling or stash them away with git-stash(1).
But then you can also find advice that pulling into a dirty is very bad, e.g.:
Avoid git-pull!
git-pull should never get invoked if you have dirty files lying around or if your branch is ahead of master.
This will always lead to some dirty artifacts in the commit history
Is there an easy answer to which perspective is best, or is this somehow a case-by-case thing?
Followup: Would using "git pull --rebase" rather than just "git pull" change the answer at all? Rebasing may have its own pitfalls in some cases, but so far my guess is that having a dirty working tree/index wouldn't make a rebase more problematic than it otherwise would be.