Everything was going well with your Drupal setup on local and then GIT STRICKS BACK. You are trying to do a git checkout and moving to a different branch but now you have an error of GIT not able to unlink file and a modified file.
git checkout develop error: unable to unlink old 'docroot/sites/default/settings.php': Permission denied Checking out files: 100% (13948/13948), done. M docroot/sites/default/settings.php Switched to branch 'develop' Your branch is behind 'upstream/develop' by 9 commits, and can be fast-forwarded. (use "git pull" to update your local branch)
And as recommended by our good friend GIT we try to do "git pull" but no luck. After this, we straight away go to use "sudo" and checkout the Drupal settings.php file which messes up the things even more.
So what is the solution?
The first thing we need to understand is this is not the issue with the file but with the directory itself, which most probably have permission 'w'. So the command which you should be running to fix this directory is
chmod ug+w sites/default
After this, you should be able to simply check out the settings.php to revert the changes and you are good to go with your Drupal stuff