'git apply' failed with code 128:'fatal: Unable to create '/Users/.../.git/index.lock': Permission denied '

Running Sourcetree 2.0.3 on Mac OSX 10.10.1 and attempting to commit a change. When I click the Stage hunk button I receive the error:

'git apply' failed with code 128:'fatal: Unable to create '/Users/.../.git/index.lock': Permission denied'

I cannot commit changes.

I am able to do this through Terminal if a add sudo. My guess it is a permissions thing somewher, but I cannot figure it out.

Any help will be greatly appreciated.

1 answer

1 accepted

This widget could not be displayed.

Check the ownership of the .git folder. It should be writable by your user. If that is not the problem, check whether the index.lock file exists, and you may need to delete the lock file manually, but only if you're sure git isn't performing any operations (shut down sourcetree to avoid colliding with automatic fetches).

Thank you, Seth.

That allowed me to attempt the commit. When I did I received a message regarding permissions being denied to COMMIT_EDITMSG.
I changed that in Terminal and then received this error:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/13/7_nt5m7x6zv4v0f5cftwvry40000gp/T/SourceTreeTemp.epR05C 

error: insufficient permission for adding an object to repository database .git/objects

fatal: failed to write commit object

Completed with errors, see above

When I look at these items in terminal they are all owned by root, but not my user. Why is this? Can I change all he ownership under .git to my user with 'chown -R'?

I think that should work, but my knowledge is based on linux, not Mac, so you may want to get a second opinion before attempting that. If everything is owned by root, it's likely that the command you used to create them (git clone?) was executed as root (probably via sudo, based on reference to that in your question). In practice, I would avoid using the "sudo" command in your user's directory for any operation other than changing ownership to your user.

Thanks Seth. 

I did try this and it worked. Thanks for the warning about sudo.

Jedidiah

Glad to help. If you hit the checkbox by my answer, that will highlight it as the "correct" answer.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

872 views 2 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you