38

i created a folder called "try" in the path /home/bhishan/Copy/try then inside that folder i gave some commands:

my commands are follwing:

curl -s -O \
http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain

chmod u+x git-credential-osxkeychain

sudo mv git-credential-osxkeychain `dirname \`which git\``

git config --global credential.helper osxkeychain

git init

git remote add origin https:

git remote add origin https:

git push origin master

==============================

it worked fine but, when i try to delete try folder i cannot delete the folder. i also can not give command:

git init

inside the try folder ( i have a .git folder there)

=====================================================

my command line and error report is this:

bhishan@bhishan-HP-Pavilion-dv6-Notebook-PC:~/Copy/try$ git init
error: could not lock config file /home/bhishan/Copy/try/.git/config: Permission denied

now, my question is how can i delete the folder called "try" ?

0

5 Answers 5

49

These kinds of problems occur when you use sudo to run commands with side effects such as file creation.

It's quite common to find files and directories in your home directory that are owned by root. In this case it seems your .git/config file is owned by root and thus gives you the permissions error when you try to lock it.

sudo chown bhishan -R .git from the ~/Copy/try directory should fix the permissions issue.

1
  • 19
    I am running Windows 10, and Git decided it was going to use my work email, so it was throwing 403 on git push. I did git config --system --unset credential.helper and it said permission denied, so I checked the file C:\Program Files\Git\mingw64\etc\gitconfig and it showed it was owned by Administrator, so I closed PowerShell and ran it again as Administrator, and git config --system --unset credential.helper ran successfully.
    – agm1984
    Apr 4, 2017 at 3:49
4

I'm adding answer to this question because I ended up here while trying to resolve quite almost the same issue.

Had that issue also in git. But for what I know, it's not just my git that is having the permission denied issue but the whole application folder. and even if I try to use git in another project, it works fine.

To add up with @Aaron D's answer, you can use $(whoami) instead of bhishan. Just like this:

$ sudo chown $(whoami) ~/Copy/try

https://stackoverflow.com/a/52315546/4477550reference

P.S. To answer your question:

now, my question is how can i delete the folder called "try" ?

You can run this command:

$ sudo rm -rf /home/bhishan/Copy/try
2
git init

This worked for me in the case where .git folder is deleted.

3
  • 1
    This is not a recommended solution, as you are deleting the git repository and version information and starting again from scratch. Your commit history will be gone. If it's a shared repository (and not just standalone on your computer), then this will definitely not work.
    – Aaron D
    Nov 27, 2020 at 18:59
  • 3
    Dont do this, it destroyed a lot of my work Apr 20, 2021 at 17:37
  • @DanielKobe I agree. I had mentioned that this worked for me in the case of .git folder is missing/deleted. If the .git folder is missing you've already lost that work. Apr 20, 2021 at 20:17
0

I was struggling with this problem and git config http.postBuffer 157286400 worked successfully in my case.

1
  • It is helpful if you wrap inline code snippets with backticks to mark it as inline code. See the StackOverflow editing help docs for examples and guides on how to effectively format your questions and answers
    – Clay H
    Oct 8, 2021 at 14:11
-1

In my case, I just used git init command and it was all working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.