Staging files with to long filenames (260+) stages the file for delete instead of modify
Asked by Kenny De Smedt:

I'm using windows 7 and sourcetree 1.9.10.0 with following in my git config file

core.symlinks=false  
core.autocrlf=true  
core.fscache=true  
color.diff=auto  
color.status=auto  
color.branch=auto  
color.interactive=true  
help.format=html  
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt  
diff.astextplain.textconv=astextplain  
rebase.autosquash=true  
credential.helper=manager  
core.longpaths=true  
user.name=myuser  
user.email=myuser@mail.com  
core.excludesfile=C:\\Users\\myuser\\Documents\\gitignore_global.txt

You notice the core.longpaths option there. I can checkout my project from bitbucket perfectly and work on it in inteliJ. However when I try to stage a file longer then 260 chars sourcetree stages it for delete. I can commit the file just fine with command line git or even in inteliJ.

Is this a bug in the current sourcetree or can this be fixed with a parameter ? This is a very dangerous development cause if a code reviewer misses this in one pull request the project code if not unit tested properly could get messed up.


Answers:
author: Ana Retamal
body: Hi Kenny! The 260 character file path limit comes from the Windows side and was fixed on Windows 10, you can read more about it at [Why does the 260 character path limit exist in Windows?](http://stackoverflow.com/questions/1880321/why-does-the-260-character-path-length-limit-exist-in-windows)

Regarding the long name files being staged for deletion, you can follow these steps to fix the issue:

* Download and install the [latest Git](https://git-scm.com/download/win)
* Enable longpaths with 'git config core.longpaths true'
* Make sure that SourceTree is using the System's Git and not the embedded one. You can check that at **Tools \> Options \> Git \> Use System Git**

After this, you'll be warned with a "Filename too long" message instead of having your files staged for deletion.

Thanks to Matej Drolc for putting this together in his blog [msysgit-longpath](http://pingec.si/blog/articles/msysgit-longpath/). I'll also open a bug ticket to see if we can get SourceTree's embedded Git to respect the longpath settings.

Hope this helps, Kenny :)

Cheers,

Ana

comments: author: Kenny De Smedt
body: Hey Ana,

I followed all the steps but the problem persists. This is my current git config

```
core.symlinks=falsecore.autocrlf=truecore.fscache=truecolor.diff=autocolor.status=autocolor.branch=autocolor.interactive=truehelp.format=htmldiff.astextplain.textconv=astextplainrebase.autosquash=truehttp.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crtdiff.astextplain.textconv=astextplainfilter.lfs.clean=git-lfs clean -- %ffilter.lfs.smudge=git-lfs smudge -- %ffilter.lfs.required=truefilter.lfs.process=git-lfs filter-processcredential.helper=manageruser.name=<<My User>>user.email=<<My Email>>core.excludesfile=C:\Users\MyUser\Documents\gitignore_global.txtcore.repositoryformatversion=0core.filemode=falsecore.bare=falsecore.logallrefupdates=truecore.symlinks=falsecore.ignorecase=truecore.longpaths=trueremote.origin.url=<< my remote orgin url >>remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*branch.develop.remote=originbranch.develop.merge=refs/heads/developbranch.master.remote=originbranch.master.merge=refs/heads/mastergitflow.branch.master=mastergitflow.branch.develop=developgitflow.prefix.feature=feature/gitflow.prefix.release=release/gitflow.prefix.hotfix=hotfix/gitflow.prefix.support=support/
```

This is my git version now

$ git --version  
git version 2.12.2.windows.2

I double checked and sourcetree is using the system git instead of the embedded git, I checked three times to be sure. I also fully rebooted my machine cause well ... windows ... but the problem still persists. I can commit and push fine using git bash just sourcetree keeps staging for delete.

Maybe it just can't work on windows 7 ?


author: Ana Retamal
body: Hi Kenny, I've submitted a bug report for that, you can track it at [SRCTREEWIN-7075](https://jira.atlassian.com/browse/SRCTREEWIN-7075). Please watch that pages for updates on this issue :)

Edit: Realised there was already a ticket for that, please follow [SRCTREEWIN-6606](https://jira.atlassian.com/browse/SRCTREEWIN-6606).

Cheers!

Ana


author: Delta Systems
body: Add the line

```
longpaths = true 
```

to your .gitconfig file under the \[core\] section.

The .gitconfig file is probably in your C:\\Users\\\<username\>\\ folder

Restart bitbucket and try the clone again.

![gitconfig.png](https://community.atlassian.com/t5/image/serverpage/image-id/33016iE4B2FDD2E52C290E/image-size/large?v=v2&px=999 "gitconfig.png")


author: Gael
body: Hi,

I'm on Windows 10 with SourceTree 2.6.10.0 and Git 2.18.0 and I had a problem staging a file path of 268 character.  

SourceTree error message was : "fatal: pathspec 'my_very_long_path' did not match any files

I had the "longpaths = true" line under the \[core\] section of my ".gitconfig" file.

I solved the problem staging file with "Git Bash terminal" and command line :

git add "my_very_long_path"


author: Rickey Marchram
body: LongPath files are too irritating, I use Long Path Tool for this.


author: Martin Miller
body: Long Path Tool is effective for solving path too long files. Try using it.


author: Martin Miller
body: Hey, have you tried using Long Path Tool? I have been using it for months now and feel like it has solved most of my problems.


author: Damien Brock
body: You can use tools like Long path tool


author: Juan Miller
body: Use "Long Path This very useful if you are having problems  
in deleting, unlocking, copying and even renaming files, also very easy.


author: DanielBrock
body: "Long path tool" is very helpful for this problem. You can solve this problem like copy, delete, long path files by using this tool.I used to have similar problems too, but after using "long path tool" everything was solved.


author: DanielBrock
body: I would like to suggest you, try LongPathTool program to resolve this issue.


author: Delta Systems
body: Add the line

```
longpaths = true 
```

to your .gitconfig file under the \[core\] section.

The .gitconfig file is probably in your C:\\Users\\\<username\>\\ folder

Restart bitbucket and try the clone again.

![gitconfig.png](https://community.atlassian.com/t5/image/serverpage/image-id/33017iA23A1CE4141CD360/image-size/large?v=v2&px=999 "gitconfig.png")


author: Kevin Howlett
body: The problem of too long file names can be solved easily with programs like Long Path Tool.