Git status only showing newly created files after becoming root - macos

I have an empty repo and cloned it on my local machine.
Next I have created created some files.
When running git status in the terminal (in the project directory), no files show up as user, but when I run it as root they are visible.
I've installed git via the git installer for OSX, installed XCode command line tools, and added git to $PATH.
I'm also using the Atlassian SourceTree app.
Same problem, but when I run this app as root, it sees the new files.
Anybody got an idea of what can be the problem?
Best,
Richard

You should not run git as root user, and you should never ever run git as root user on a project which your normally use as normal user.
Running git as root will create files belonging to root (e.g. .git/index, ...) which your normal user won't be able to update later.
Solution:
run chown to restore the correct ownership
stop using git as root.

Do you have permission as user to view the folder files? sounds like the permissions are for root only
ls -la in terminal will show you the group and owner. If your user is not in the group or not the owner you will not be able to read the folder content.
How to fix?
sudo chmod 655 .
how to verify the problem?
Open terminal as user and try to list the file content. If you can cant see the files change the group or permissions of the folder so everyone (or whoever you choose) can read/write to this folder.

Related

Cloning git repo on Windows 10 changing file permissions under Users directory

So, I had an SSD failure last night and have been reinstalling my coding environment again today but have encountered a strange issue: whenever I clone my repos now they're being assigned 700 permissions for every file and folder, which breaks several things in vagrant/puppet/npm/apache, and more specifically it ignores the ACL settings when using rsync to synchronize the files to a virtual machine, leaving them with the same permissions on the host.
I tried manually updating the permissions on all the files, and that worked for most things, but broke something in NPM we need to build our javascript and css, and likewise adding --chmod=ugo=rwX to rsync fixes the permissions sort of, but leaves NPM failing, which worked with the permissions still broken.
After fighting with that for a while I discovered something that appears to be new:
Even with permissions set to 755 (or whatever) on the parent directory, every cloned file under C:\Users\James\ just always defaults to 700. I had previously had my development environment set up in the exact same place without issues, so fairly sure this is something relatively new, but cloning the repos into C:\Code\ or any other location that's not under C:\Users\ creates the files with the expected permissions, and everything works again.
So I guess the moral of the story is: don't clone git repos under the Users directory, unless you want Windows to break all your file permissions.

Operation not permitted and permission denied

My mac version is 10.12.2.
I'm trying to install R studio and a number of other softwares, but it doesn't work. I suspect it's because of permission issues - my mac doesn't allow them to create directories during installing.
~$ pwd
/Users/biona001
~$ mkdir fdsa
mkdir: fdsa: Operation not permitted
but if I'm in a higher director, it says something different
~$ cd ../
Users$ pwd
/Users
Users$ mkdir fdsa
mkdir: fdsa: Permission denied
and if I move into a lower directory, it works
Users$ cd biona001/Documents/
Documents$ mkdir fdsa
Documents$
I googled almost everything without finding anything that worked, including the one where I boot my mac into this weird mode and type some command. I should be the administrator of this mac.
R Studio is installed by dragging the application to your applications folder. It requires R to be installed. R can be installed from a package, so you don't need the command line.
The 'administrator' on the mac, does not have permission to write files or create folders anywhere. It's not a good idea in any case.
If it's absolutely necessary, you must enable 'root' and login as root. But this is not necessary to use R Studio and R.
Enabling root access without knowing exactly what you are doing is a recipe for disaster.
I had the same "operation not permitted" issue on MacOS Sierra.
Looking at the user's home folder in Finder as John Elemans recommended, showed that the home folder was locked. Unchecked the locked checkbox in finder and was able to create a subfolder in the user's home folder via terminal.

Git commands require sudo on OSX

I've moved back from my work MBP to my home MBP. The work one allowed to run git commands without the need for sudo. But I'm finding this is a requirement on my home machine.
I would prefer to be able to run git commands without sudo.
I looked at the git commands in /usr/bin, and they all have rwxr-xr-x (755), and are owned by root and group wheel. I suppose I could change this to rwxrwxrwx (777), but I'm wondering if there's a better way. I'm thinking of adding my user to the wheel group; but would there be other side effects?
The permission on the git executable are fine; there is no reason you should need to change that, or change your group.
It's more likely that the permissions on your Git checkout are wrong. If you accidentally checked it out with something like sudo git clone ssh://user#host/project.git, or at some point you performed some kind of operation in the repository that caused some files to be owned by root, git running under your account won't be able to write to those files.
Most likely, what you need to do is chown -R <user> myproject in order to make your project owned by your own user account, rather than root.
If you were prompted like this:
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
And then you ran:
sudo git init .
After updating xcode license. Just remove the init and re-init w/o sudo
sudo rm -rf .git
git init .
This fixed my issue.

Git not getting write access

I have recently bought a Windows 8 machine and I'm attempting to install Git. I think I have it all working correctly (I have done this correctly a few ties before). However, when I try to clone one of my repos from Github, I get the following error.
fatal: could not create work tree dir '..': Permission Denied
I am trying to do this inside C:\inetpub\wwwroot, would this be a windows "sensitive information" folder? In which case, how do I let it be edited by programs? (If that's what it's even called)
Or, if I only need to run this in administrator mode, how would I be able to do this when I right click in the folder and select "Git Bash Here" ?
Thanks in advance!
Disable UAC, make sure that you are logged in as full Administrator and run Git as Administrator too.

remove .git/index.lock': Permission denied

I'm completely stuck as to why my git has completely locked me out. I have a laptop that I use at work and when I'm home. For both accounts I use git extensively and both are located in different paths. Today I came into work and I can't do anything, all I see is:
/Applications/MAMP/htdocs/my_site/.git/index.lock': Permission denied
For all I care the branch I'm on can be deleted. I've tried removing the branch, checking out any other branch, removing the index.lock file (as suggested by other users on sites). I only have the terminal window open, no other possible programs using git (as far as I know and nothing noticeable in the activity window). I have rebooted the computer straight into my work account and still no luck. How can I remove this lock?
I had the exact same problem wanting to commit my changes to git, and solved it this way:
I needed to change the group of my .git folder and its contents:
sudo chown -R <owner>:<group> .git
needed to change the permission of this folder:
sudo chmod -R 775 .git
Check which user owns the git lock:
ls -la /Applications/MAMP/htdocs/my_site/.git/index.lock
Then you can use sudo to remove it.
After updating xcode you are maybe asked for agreeing to the new license.
git init
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
When you do this
sudo git init
you'll get a root user .git dir
drwxr-xr-x 10 root XXXX 340 25 Sep 12:40 .git
If you call other git commands which create files, these files are also created for the root user.
Change the permissions or remove .git if you don't need it yet.
=> Don't ever call git with sudo!!!
If your are asked to just call git on an empty directory
mkdir foo
cd foo
sudo git init
I had this issue as I running the following command
sudo git fetch && git checkout<branch>
Note the second sudo was missing. Running the following solved the issue:
sudo git fetch && sudo git checkout<branch>
You shouldn't have to change the owner ship of the .git directory when running sudo.
I was experiencing the same issue when trying to update the submodules of my repo:
$ git submodule update
fatal: Unable to create '.../.git/modules/deps/luajit/index.lock':
Permission denied
Unable to checkout '04dc64b558025e76a820f89a8e41840bf8269f32' in
submodule path 'deps/luajit'
It seems the problem was the submodules belonged to a different user, so I set back the ownership to me:
cd .git/modules/
chown -R user.group *
My computer system is Windows. When I open WSL remote vscode and local vscode in this path, system show this error. I closed remote vscode WSL and it solved this problem.
Change the permissions from root to the current user for the /.git folder
sudo chown username .git
Checking permission is surely the way. I faced this error when logged in with the wrong account. So, answer from my personal experience is:
"Be sure you logged in with the correct account".

Resources