Sometimes git clone
results a dirty worktree. I get it, you commit text files with crlf
, you configure .gitattributes
to force lf
, and set autocrlf
to true
- you are asking for trouble. But why under the same conditions you would sometimes get a dirty worktree, and sometimes - clean?
Working with Git for Windows 2.40.1 (confirmed not to be platform or version specific in general, but the repro seems to be Windows specific). The only setting I have changed is set core.autocrlf=true
. Here is the script that repeatedly clones a repo and checks if it's dirty. Well, technically, it just refreshes the index, but you can reproduce the same with a clean clone, just takes longer.
#!/usr/bin/env bash
set -e
# Continuously reset a repo and check its status
REPO_URL="https://github.com/balakine/crlf.git"
REPO_DIR="crlf"
COUNT_TOTAL=0
# Clone the repository
rm -rf "$REPO_DIR"
git clone --branch master --single-branch --depth=1 "$REPO_URL" "$REPO_DIR"
cd "$REPO_DIR"
until git diff --quiet; do
((++COUNT_TOTAL))
# Reset the repository
git rm --quiet --cached -r .
git reset --quiet --hard
printf "\033[0;32mTotal: %s\033[0m\n" "$COUNT_TOTAL"
done
git status
It will take a while, about 5,000 tries on my machine, but you will get a clean repo at some point. Why? I have an example of a repo that clones clean 8/100, but it's proprietary.