# Gitattributes file is not respected when switching between branches

5 messages from 2016-09-12 to 2016-09-18. Participants: Виталий Ищенко, Torsten Bögershausen.
Thread: https://gitlist.dev/t/44064

## Виталий Ищенко, 2016-09-12 12:55

Subject: Gitattributes file is not respected when switching between branches
Message-ID: <CANYoZJng0GNZWU=eUEnXgVQ_NKQQOKM+mhJ9bsXMEJxxEhwQMw@mail.gmail.com>
URL: https://gitlist.dev/e/CANYoZJng0GNZWU%3DeUEnXgVQ_NKQQOKM%2BmhJ9bsXMEJxxEhwQMw%40mail.gmail.com

```
Good day

I faced following issue with gitattributes file (at least eol setting)
when was trying to force `lf` mode on windows.

We have 2 branches: master & dev. With master set as HEAD in repository

I've added `.gitattributes` with following content to `dev` branch

ˋˋˋ
* text eol=lf
ˋˋˋ

Now when you clone this repo on other machine and checkout dev branch,
eol setting is not respected.
As a workaround you can rm all files except .git folder and do hard reset.

Issue is reproducible on windows & unix versions. Test repo can be
found on github
https://github.com/betalb/gitattributes-issue

master branch - one file without gitattributes
feature-branch - .gitattributes added with eol=lf
unix-feature-branch - .gitattributes added with eol=crlf

Thanks,
Vitalii

```

## Torsten Bögershausen, 2016-09-12 19:35

Subject: Re: Gitattributes file is not respected when switching between branches
Message-ID: <8df2883f-ec3c-3446-2e06-207c93452332@web.de>
URL: https://gitlist.dev/e/8df2883f-ec3c-3446-2e06-207c93452332%40web.de
In-Reply-To: <CANYoZJng0GNZWU=eUEnXgVQ_NKQQOKM+mhJ9bsXMEJxxEhwQMw@mail.gmail.com>

```
On 12.09.16 14:55, Виталий Ищенко wrote:
> Good day
>
> I faced following issue with gitattributes file (at least eol setting)
> when was trying to force `lf` mode on windows.
>
> We have 2 branches: master & dev. With master set as HEAD in repository
>
> I've added `.gitattributes` with following content to `dev` branch
>
> ˋˋˋ
> * text eol=lf
> ˋˋˋ
>
> Now when you clone this repo on other machine and checkout dev branch,
> eol setting is not respected.
> As a workaround you can rm all files except .git folder and do hard reset.
>
> Issue is reproducible on windows & unix versions. Test repo can be
> found on github
> https://github.com/betalb/gitattributes-issue
>
> master branch - one file without gitattributes
> feature-branch - .gitattributes added with eol=lf
> unix-feature-branch - .gitattributes added with eol=crlf
>
> Thanks,
> Vitalii
Some more information may be needed, to help to debug.

Which version of Git are you using ?
What does

git ls-files --eol

say ?



```

## Torsten Bögershausen, 2016-09-12 19:42

Subject: Re: Gitattributes file is not respected when switching between branches
Message-ID: <7c14756e-29f9-b475-f5f5-597acb8cea98@web.de>
URL: https://gitlist.dev/e/7c14756e-29f9-b475-f5f5-597acb8cea98%40web.de
In-Reply-To: <8df2883f-ec3c-3446-2e06-207c93452332@web.de>

```
On 12.09.16 21:35, Torsten Bögershausen wrote:
> On 12.09.16 14:55, Виталий Ищенко wrote:
>> Good day
>>
>> I faced following issue with gitattributes file (at least eol setting)
>> when was trying to force `lf` mode on windows.
>>
>> We have 2 branches: master & dev. With master set as HEAD in repository
>>
>> I've added `.gitattributes` with following content to `dev` branch
>>
>> ˋˋˋ
>> * text eol=lf
>> ˋˋˋ
>>
>> Now when you clone this repo on other machine and checkout dev branch,
>> eol setting is not respected.
>> As a workaround you can rm all files except .git folder and do hard reset.
>>
>> Issue is reproducible on windows & unix versions. Test repo can be
>> found on github
>> https://github.com/betalb/gitattributes-issue
>>
>> master branch - one file without gitattributes
>> feature-branch - .gitattributes added with eol=lf
>> unix-feature-branch - .gitattributes added with eol=crlf
>>
>> Thanks,
>> Vitalii
> Some more information may be needed, to help to debug.
>
> Which version of Git are you using ?
> What does
>
> git ls-files --eol
>
> say ?
Obs, All information was in the email.

tb@xxx:/tmp/gitattributes-issue> git ls-files --eol
i/lf    w/lf    attr/                   testfile-crlf.txt
tb@xxx:/tmp/gitattributes-issue> ls -al
total 8
drwxr-xr-x   4 tb    wheel  136 Sep 12 21:38 .
drwxrwxrwt  19 root  wheel  646 Sep 12 21:38 ..
drwxr-xr-x  13 tb    wheel  442 Sep 12 21:38 .git
-rw-r--r--   1 tb    wheel   60 Sep 12 21:38 testfile-crlf.txt
tb@xxx:/tmp/gitattributes-issue>

Could it be that you didn't commit the file ".gitattributes" ?
This could help:
git add .gitattributes && git commit -m "Add .gitattributes"








```

## Виталий Ищенко, 2016-09-16 06:51

Subject: Re: Gitattributes file is not respected when switching between branches
Message-ID: <CANYoZJnB81rEGNAjGj6jOscmdSW_niSy6jRP6acw2xB4ssX8xA@mail.gmail.com>
URL: https://gitlist.dev/e/CANYoZJnB81rEGNAjGj6jOscmdSW_niSy6jRP6acw2xB4ssX8xA%40mail.gmail.com
In-Reply-To: <7c14756e-29f9-b475-f5f5-597acb8cea98@web.de>

```
Sorry for delay.

".gitattributes" indeed is not present in "master", but this is intentionally
It is placed only in following 2 branches:
feature-branch
unix-feature-branch

This is how flow looks on windows
$ git --version
git version 2.9.3.windows.1

vitalii.ishchenko@DESKTOP-9TC9UPB MINGW64 /c/work/repos/gitattributes (master)
$ git ls-files --eol
i/lf    w/crlf  attr/                   testfile-crlf.txt

vitalii.ishchenko@DESKTOP-9TC9UPB MINGW64 /c/work/repos/gitattributes (master)
$ git checkout feature-branch
Switched to branch 'feature-branch'
Your branch is up-to-date with 'origin/feature-branch'.

vitalii.ishchenko@DESKTOP-9TC9UPB MINGW64 /c/work/repos/gitattributes
(feature-branch)
$ git ls-files --eol
i/lf    w/lf    attr/text eol=lf        .gitattributes
i/lf    w/crlf  attr/text eol=lf        testfile-crlf.txt



On Mon, Sep 12, 2016 at 10:42 PM, Torsten Bögershausen <tboegi@web.de> wrote:
> On 12.09.16 21:35, Torsten Bögershausen wrote:
>> On 12.09.16 14:55, Виталий Ищенко wrote:
>>> Good day
>>>
>>> I faced following issue with gitattributes file (at least eol setting)
>>> when was trying to force `lf` mode on windows.
>>>
>>> We have 2 branches: master & dev. With master set as HEAD in repository
>>>
>>> I've added `.gitattributes` with following content to `dev` branch
>>>
>>> ˋˋˋ
>>> * text eol=lf
>>> ˋˋˋ
>>>
>>> Now when you clone this repo on other machine and checkout dev branch,
>>> eol setting is not respected.
>>> As a workaround you can rm all files except .git folder and do hard reset.
>>>
>>> Issue is reproducible on windows & unix versions. Test repo can be
>>> found on github
>>> https://github.com/betalb/gitattributes-issue
>>>
>>> master branch - one file without gitattributes
>>> feature-branch - .gitattributes added with eol=lf
>>> unix-feature-branch - .gitattributes added with eol=crlf
>>>
>>> Thanks,
>>> Vitalii
>> Some more information may be needed, to help to debug.
>>
>> Which version of Git are you using ?
>> What does
>>
>> git ls-files --eol
>>
>> say ?
> Obs, All information was in the email.
>
> tb@xxx:/tmp/gitattributes-issue> git ls-files --eol
> i/lf    w/lf    attr/                   testfile-crlf.txt
> tb@xxx:/tmp/gitattributes-issue> ls -al
> total 8
> drwxr-xr-x   4 tb    wheel  136 Sep 12 21:38 .
> drwxrwxrwt  19 root  wheel  646 Sep 12 21:38 ..
> drwxr-xr-x  13 tb    wheel  442 Sep 12 21:38 .git
> -rw-r--r--   1 tb    wheel   60 Sep 12 21:38 testfile-crlf.txt
> tb@xxx:/tmp/gitattributes-issue>
>
> Could it be that you didn't commit the file ".gitattributes" ?
> This could help:
> git add .gitattributes && git commit -m "Add .gitattributes"
>
>
>
>
>
>
>

```

## Torsten Bögershausen, 2016-09-18 19:31

Subject: Re: Gitattributes file is not respected when switching between branches
Message-ID: <beaf2e9c-70c9-b80a-b201-aeed830f8807@web.de>
URL: https://gitlist.dev/e/beaf2e9c-70c9-b80a-b201-aeed830f8807%40web.de
In-Reply-To: <CANYoZJnB81rEGNAjGj6jOscmdSW_niSy6jRP6acw2xB4ssX8xA@mail.gmail.com>

```
On 16.09.16 08:51, Виталий Ищенко wrote:
> Sorry for delay.
> 
No problem about the delay.

(And please no top-posting)


If you say
> ".gitattributes" indeed is not present in "master", but this is intentionally
then nobody has (to my knowledge) thought about this situation/workflow yet.


The short version:
Git is designed to have the same .gitattributes in different branches.
At least not in the long run.

A typical use case is to create a repo, adjust the
.gitattributes and keep this in all branches.



 




```
