The Repository is Locked - Error while trying to commit into source control

It's just a common issue faced if two or more git operations are done by your system and that generates a lock file.

All you need to do is:

  1. Close Xcode
  2. Open the .git folder in your xcode project folder. The folder is hidden, so you would need to either use terminal to open the directory or the "Go to Folder" option in Finder.
  3. Then delete the "index.lock" file. Either through terminal or Finder.
  4. Try and commit again.
  5. If it fails again, repeat 1 to 3 but commit first with terminal.

If you know what you're doing just typing this command into terminal in the current directory of your project and it should delete the lock file: rm -f .git/index.lock

If anything you can check this Quora question for more details on what you've faced: https://www.quora.com/Why-do-my-git-operations-often-fail-with-a-lock-error

Hope that helps you guys, and happy coding!


Also make sure the simulator is not running while you are commiting. Close both simulator and Xcode. then restart and try again