Git errors on Homestead and Windows

Daniel KoopHomesteadLeave a Comment

I like Homestead very much but it is a bit of a hassle to get it running on Windows. Since a colleague did not own a Mac but a Windows computer, I was forced to find a way how you can install Homestead there. But there was a conflict: my colleague updated the git repository via Git bash and not Homestead. The results was that he had git errors on Homestead and Windows.

Best Git practice for Homestead, Git and Windows

In Windows, you can enter your virtual machine via SSH just like on OS X. However, you can also choose to use Gitbash instead of SSH to manage your git data. This ease of access also comes with a major drawback. Windows has a different way to store new lines in files than Linux (Homestead is based on Debian, which is Linux). Windows uses \r\n and Linux \n for new lines. So when you update git in Windows and modify files in Homestead, it is likely that you will find Git failingĀ on pulling or committing files.

Instead, you should only use Git inside your VM. This will prevent that you experience git errors on Homestead and Windows because there is a consistency in how the new lines are handled.

What to do when you have Git errors on Homestead and Windows

Unfortunately I did not save the original error, but in my case I did not have had any commits pending for pushing or any changed code. If you do have code already committed, the best solution is probably to push those commits before you take action. When you have done that, you can use the following steps to reset git. Please note that any code that is not pushed to the server gets lost (including stashed code) and any configuration to git (like the remote servers). Also note that you should run this inside HomesteadĀ only.

rm -rf .git
git init
git add -A .
git remote add origin git://user@host/some_repository.git
git pull master

Git is now reset to the latest commit of origin.