1

I have issues using git commands after I did "git clean -f -X". The only commands I can only use "git status" and "git branch". I don't have anything that I care to commit since I just started this branch locally. Any suggestions?

I have tried to remove "rm -rf .git/index.lock" and I even tried "git reset HEAD^" but it throws that message of Permission denied.

rm -rf .git/index.lock git reset HEAD^

I would like to use all git commands.

user2537246
  • 143
  • 2
  • 10
  • What are the permissions for the directory you are working in? – Emil Vatai Jul 13 '19 at 04:31
  • For .git under that repo file I have dr-xr-x--- – user2537246 Jul 13 '19 at 04:47
  • You need to give yourself write permission on the directory. Make sure you own it (`ls -ld .git`) and if not, change the owner to yourself, then use `chmod u+w .git` to give yourself write permission. – torek Jul 13 '19 at 04:59
  • 1
    To give precise information about permissions you'd need to include more information, such as user and group. I assume you can check it yourself if the permissions are ok, I just wrote the comment as a potential reminder. Another thing to check is the parent directory. All in all I'd say you are giving very little information to go on... from what you are disclosing, the answer would be "It should work"... so please provide more info! :) (e.g. the exact error message, and a few `ls -l` outputs) – Emil Vatai Jul 13 '19 at 13:00
  • Thank you Emil, it was a permission for sure so I gave chmod 755 folder and it worked! – user2537246 Jul 13 '19 at 19:38
  • You have the up arrow for saying thank you! – Emil Vatai Sep 19 '19 at 11:06

5 Answers5

2

This is because you don't have access to this folder. So to give access you can run the following command in the terminal.

sudo chmod -R 777 /path/to/your/folder

Hopefully, it will work for you. Thanks

Yisal Khan
  • 359
  • 3
  • 10
0

rm -f /xxx would not work because '/' would refer to the root folder, usually owned by root.

This could work:

cd /path/to/my/repo
rm -f .git/index.lock

The OP user2537246 confirms in the comments a permission issue:

I gave permission 755 and it worked!
I didn't have to move anything.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @user2537246 What is your error message when you delete from the repo folder itself? And did you remove the first `/` in `rm -f /...`? (to be sure and *not* delete from root folder). – VonC Jul 13 '19 at 05:13
  • I didn't get an error when I deleted it from folder. Yes I did try without the `/` – user2537246 Jul 13 '19 at 05:18
  • @user2537246 root folder is not where you want a Git repository: move it to your `$HOME` folder: `~/myrepo/.git`, and chown it to your account. – VonC Jul 13 '19 at 05:22
  • I gave permission 755 and it worked! I didn't have to move anything. Thank you guys! – user2537246 Jul 13 '19 at 19:36
  • @user2537246 Great! I have included your comment in the answer for more visibility. – VonC Jul 13 '19 at 19:41
0

Based on the discussion in the comments, it was a permissions issue. If git can't write your .git directory, git won't work.

Emil Vatai
  • 2,298
  • 1
  • 18
  • 16
0

for the above issue instead of removing the index.lock file ,you have to use sudo command before git commands to resolve it. try to execute commands as root user

sudo git checkout -b or use sudo before any git command to resolve the issue.

lavanya
  • 106
  • 3
0

For if any windows user stumbles on this:

I faced same issue and it wasn't solved by permissions since I had all the permissions assigned. Removing index.lock didn't help either.

I tried with WSL and it showed this error:

Another git process seems to be running in this repository.

Based on this I quit every process run by VS Code (that is the IDE I am using) and voila everything back to normal.

Note: Merely closing VS Code didn't help, had to end all processes from task explorer.

On a larger point, try ending all the processes via which you were using git. For me it was just VS Code.

nu_popli
  • 920
  • 1
  • 7
  • 12