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" ?

Jason Hu
  • 6,239
  • 1
  • 20
  • 41
BhishanPoudel
  • 15,974
  • 21
  • 108
  • 169

5 Answers5

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.

Aaron D
  • 7,540
  • 3
  • 44
  • 48
  • 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 04 '17 at 03: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
Vince Banzon
  • 1,324
  • 13
  • 17
2
git init

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

PavanBhushan
  • 106
  • 2
  • 8
  • 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 '20 at 18:59
  • 3
    Dont do this, it destroyed a lot of my work – Daniel Kobe Apr 20 '21 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. – PavanBhushan Apr 20 '21 at 20:17
0

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

  • It is helpful if you wrap inline code snippets with backticks to mark it as inline code. See the [StackOverflow editing help](https://stackoverflow.com/editing-help#code-spans) docs for examples and guides on how to effectively format your questions and answers – Clay H Oct 08 '21 at 14:11
-1

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