Permission denied when creating symbolic links in git - windows

there is a similar question, but the difference here is that I am working on Windows. I am running git on Windows (working in git bash tool) and I have successefully cloned my forked repository. Now I need to make symbolic link and it gives me Permission denied. I can make new dir for example in .git folder and I have also set chmod /R 777 for .git directory, so it seems I have permissions.
I tried to run:
rm -rf hooks and then ln -s ../git_hooks hooks.

You might be running into a basic incompatibility of ln on windows platforms (in this case within MINGW-MSYS). You can replace ln with a version that "does the right thing" on Windows; have a look at this:
Git Bash Shell fails to create symbolic links

I had this issue on Windows and I did a couple of steps to resolve this :
Enabled core.symlinks by modifying git config
git config --edit
Opened Git Bash as an Administrator and executed the git checkout command
This worked for me, hope it helps someone.

If you have are using Git for Windows SDK, you can install winln using the pacman package manager by running: pacman -Su winln
Then you can run: winln -s target link, it will check that you have SeCreateSymbolicLinkPrivilege, otherwise it will fail. This is equivalent to running Window's mklink.exe.
I am surprise Git for Windows, does not ship with winln vs an ln command that does a copy without telling you that it did a copy.

When installing git-bash for windows, there is an option called "Enable symbolic links". When I installed git-bash with that option I had the same issue as OP. So I installed the same setup (git-bash) again with that "Enable symbolic links" option unchecked. Then my issue was resolved.

If you are using a local web server on Windows (OpenServer, Laragon, Local), then start the server as an administrator. It worked for me

Related

How to change the command base in Git Bash in VS Code?

I'm learning to use Git. After installation I can open a Bash terminal on VS Code (I'm using Windows if that's relevant). Right after opening a Bash terminal, this command shows up automatically (the id and path are masked for privacy):
myid#machineid MINGW64 /c/Users/...
$ source C:/ProgramData/Anaconda3/Scripts/activate base
(base)
I guess it means it's using Anaconda to run the Git command. However, it appears many CMD commands that otherwise work normally in a Windows terminal don't work. For example, I can't create a new folder. This error comes up:
$ mkdir test
bash: /c/ProgramData/Anaconda3/Library/usr/bin/mkdir: Permission denied
(base)
Similarly, commands like ls or touch just don't work. But I find pwd works. I look at /c/ProgramData/Anaconda3/Library/usr/bin and see there are a bunch of CMD command exe files in there, such as mkdir.exe, rm.exe. I also look at the Git installation directory and find a folder with similar exe commands (C:\Program Files\Git\usr\bin)
On the other hand, I can still use Git commands. So this works (after manually creating the folder test):
$ git init
Initialized empty Git repository in C:/Users/.../test/.git/
(base)
Also, if I don't use VS Code, but use a Git CMD then everything works just fine.
So the question is how I can fix it? More specifically, how can I direct Git to use Git command base in VS Code instead of depending on Anaconda base? What it currently means to me is that if I uninstall Anaconda then Git may not work in VS Code at all.

GIT Issue on Windows (The filename or extension is too long)

Overview:
Just installed the GIT version 2.20.1-64-bit on my Windows 7 platform. Git works well on GIT Bash; but, any git command on Windows CMD or Powershell raises The filename or extension is too long error.
Details:
GIT version: 2.20.1-64-bit
Platform: Windows 7
Troubleshooting Efforts:
I tried switching longpaths attribute to true based on Filename too long in Git for Windows. I also googled to find other solutions but all recommended the same approach which was updating the git config.
The GIT config file updated with git config --system core.longpaths true
Issue:
Any Git command via Windows CMD or 3rd party apps like IntelliJ Idea raises the following error:
CMD:
IntelliJ:
Please advise me with your genuine solutions.
I had the same problem. I then installed it in my user folder and now it works. It seems to be a privilege issue. Git gets installed as admin in C:\Program Files\Git but then can't write to these files because it is run as a user.
Also using the portable version should fix the problem.
Try first to use a simplified PATH and a portable Git (like PortableGit-2.20.1-64-bit.7z.exe) uncompressed anywhere you want.
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
Then check if the issue persists in that CMD session, where you have set said simplified PATH.

Git "add --patch" is not working

When I type git add --patch on my Windows 10 machine in the terminal, I get the error:
git: 'add--interactive' is not a git command. See 'git --help'.
I've googled to no avail, all other problems seem to be people running into this issue using other software or on Linux. Any tips?
This thread (for Git on Linux) mentioned the lack of a git-perl package.
But that should not be the case on Windows.
For testing, download PortableGit-2.17.0-64-bit.7z.exe and uncompress its content anywhere you want.
Then setup a simplified PATH:
set G=c:\path\to\latest\git
set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
set PATH=%PATH%;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\
In that CMD session, try again your git add -p command.

warning: templates not found /usr/local/git/share/git-core/templates

I get this error warning: templates not found /usr/local/git/share/git-core/templates when I cloning repo in local repository this link, this link, and this link I tried this method and I just waiting more than 20 minutes but repo doesn't clone. I use source-tree and OS X El Capitan. How can I fix it?
Create a templates folder.
In your case, it should be: mkdir /usr/local/git/share/git-core/templates
I was also getting same error
warning: templates not found /usr/local/git/share/git-core/templates when I cloning repo in local repository then i found solution which solved my issue.
I Added the [init] section to .gitconfig in home directory, so that it looked at SourceTree's git templates directory when cloning a repo:
[init]
templatedir = /Applications/SourceTree.app/Contents/Resources/git_local/share/git-core/templates
Hope it will help you!.
In case of Source tree on macOS
Steps:
Source tree Menu
Preferences
Git
Click on System Git under Embedded Git Version 2.2.1
Reset to embedded Git
Restart source tree
Similar to Rohit's answer, I went into SourceTree's Tools->Options->Git and selected "Update Embedded Git". After the latest Embedded Git version was installed, the warning stopped occurring.
Cloning via SourceTree for Mac, the download was stuck at 99% and I was getting the same error:
warning: templates not found /usr/local/git/share/git-core/templates
I started looking up the issue and found this Question. Was about to start with some of the Answers here...
But then it finally completed. So, my Answer: wait a bit longer. Mine was cloning for 10 minutes or so.
#wonderfulthunk's comment works for me:
sudo mkdir -p /usr/local/git/share/git-core/templates && sudo chown -R my_username /usr/local/git
I followed below steps and I am able to get through this issue in Windows 10.
Step1:
First know the path of %USERPROFILE% using below command in command prompt.
echo %USERPROFILE%
Please note that, you can also run git config --list and look for init.templatedir for the path.
Step2:
Look for .git_template folder in it.
If is missing, please run below command to add it.
git config --global init.templatedir "%USERPROFILE%.git_template
Step3:
Create a folder namely templates in it.
After creating this templates folder, I did not get the warning mentioned i.e. 'templates not found' any more.
MacOS: Ventura 13.0 /
Sourcetree: 4.2.0
I fixed warning: templates not found /usr/local/git/share/git-core/templates by going to "Sourcetree preferences -> Git" and clicking to "Use System Git". There's no need to restart Sourcetree, just try to clone again.
I didn't switch to usage of embedded Git again, all works perfectly with usage of System Git.
In my case, this happened because an unaccesed project. Check that you have all the privileges to clone that repository.
If you use Sourcetree application, switch git version from "Embedded Git" to "System Git" in setting.
https://community.atlassian.com/t5/Bitbucket-questions/About-git-path-for-Sourcetree/qaq-p/186483
And after changing git version, if you still have problem with cloning, change protocol from "ssh" to "https".
I couldn't get past this problem. Even after getting rid of the 'templates not found' error by adding the usr/local/git... folder, the clone would still look like it was at 99% and sit there for HOURS. I just clone via command line and it's there in seconds, then I just add the local repo to Sourcetree instead.

How to install Git Large File Storage on Windows?

According to its doc, double-click should be enough. But when I opened git bash and ran git lfs init, it doesn't work:
$ git lfs init
git: 'lfs' is not a git command. See 'git --help'.
The only reason why "git lfs" would not be a git command would be because the git-lfs.exe hasn't been put in your %PATH%.
That is what the git-lfs-windows-amd64-0.5.3\install.bat is supposed to do.
set GIT_LFS_BIN_PATH="%LOCALAPPDATA%\GitLFS\bin"
IF EXIST %GIT_LFS_BIN_PATH% GOTO DIRECTORY_EXISTS
mkdir %GIT_LFS_BIN_PATH%
set "path=%PATH%;%GIT_LFS_BIN_PATH:"=%"
So:
Make sure install.bat was successfully executed
Check the content of "%LOCALAPPDATA%\GitLFS\bin"
make sure to open a new CMD Windows
Check your %PATH% environment variable
Just adding my 2c in case someone lands on this page..
The easiest (and I believe most "correct") option to install LFS on Windows is to use the windows' built-in winget package manager
winget install -e --id GitHub.GitLFS
I was getting the same error as you after simply running the downloaded installer, however the winget command fixed it for me.
PS. Even if you don't have winget - running winget will automatically install it from MS Store

Resources