Skip to content

Using git in Ubuntu Bash does not Sync with Native Windows git #1352

Closed

Description

When executing git status inside Ubuntu Bash on Windows, it lists many files incorrectly. A git pull on an up-to-date repo can fail with collisions.

To reproduce:

  1. Using a native windows git (e.g. in GitBash):
$ git clone https://github.com/Microsoft/BashOnWindows.git
Cloning into 'BashOnWindows'...
remote: Counting objects: 109, done.
remote: Total 109 (delta 0), reused 0 (delta 0), pack-reused 1Recei09
Receiving objects: 100% (109/109), 18.02 KiB | 0 bytes/s, done.
Resolving deltas: 100% (35/35), done.
Checking connectivity... done.

Guyon@Toruk MINGW64 /e/dev/git
$ cd BashOnWindows/

Guyon@Toruk MINGW64 /e/dev/git/BashOnWindows (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
  1. Start Ubuntu Bash on Windows and navigate to the repo directory
guyon@TORUK:/mnt/e/dev/git/BashOnWindows$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   CONTRIBUTING.md
        modified:   ISSUE_TEMPLATE.md
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

Expected Result
There should be no modified files

Actual Result
There are modified files

My Windows Build Number: Version 1607 (OS Build 14393.447)

Activity

  1. aseering commented on Nov 12, 2016

    @aseering
    Contributor

    Hi Guyon Roche (@guyonroche) -- if you type git config core.autocrlf at the two different git prompts, do you get the same value at each, or is it different?

    Windows and Linux represent newlines in text files differently. So, text files checked out on Windows will, by default, deliberately look different on disk than text files checked out on Linux. My guess is that what you're seeing here is Linux-git reporting that the files have been modified. It doesn't know that you have Windows-git installed and that Windows-git made this change. Even if it did know that, other Linux tools would not, so from their perspective this would also be a change.

    If you have a single checkout that you want to share between Windows and Linux, my recommendation would be that you reinstall Windows git and, when prompted during installation, tell it to not modify newlines. (The default is to automatically convert them on checkout and convert them back on checkin.) Most Windows programs (with the notable exception of notepad.exe) can handle Linux newlines just fine, so this shouldn't affect your workflow.

  2. Herst commented on Nov 12, 2016

    @Herst

    Maybe also has to do with file modes?

  3. guyonroche commented on Nov 13, 2016

    @guyonroche
    Author

    Interesting, running git config core.autocrlf - in Gitbash I get an output of "true". In Ubuntu bash I get no output

  4. guyonroche commented on Nov 15, 2016

    @guyonroche
    Author

    Herst - file modes looks likely...

    In Gitbash:

    $ ls -al package.json
    -rw-r--r-- 1 guyon 197609 1632 Nov  3 07:48 package.json
    

    In Ubuntu bash (same file):

    $ ls -al package.json
    -rwxrwxrwx 1 root root 1632 Nov  3 07:48 package.json
    

    Are there any workarounds for this?

  5. Herst commented on Nov 15, 2016

    @Herst

    The core.fileMode setting of git (run git config core.fileMode false).

  6. guyonroche commented on Nov 16, 2016

    @guyonroche
    Author

    Found it - I ran:

    git config core.autocrlf true
    

    in the Ubuntu bash. I guess no setting at all defaults to false. Now it ignores the \r\n differences

  7. rohitkrishna094 commented on Nov 22, 2019

    @rohitkrishna094

    Sorry for bumping this thread. But just a small note, you could do

    git config --global core.autocrlf true on ubuntu bash. This way you don't have to do this for every local repo.

    Let me know if anyone finds a problem doing this, that is if it breaks anything. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions