Why do I need Root privilege to do `git branch -a`?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 09:25:10

问题


The git repository is under my username nikhil and group nikhil as follows:

$ ls -l
drwxr-xr-x 10 nikhil nikhil 4096 Sep  1 12:33 CS/

I can get git status as git status without root privilege.

But when I try to list branches:

$  git branch -a

nothing happens.

Also, with root priviledge:

$ sudo git branch -a
[sudo] password for nikhil:
* master
  remotes/origin/feature
  remotes/origin/master

it does lists all my repository.

Why is it so?


Edit: output of ls -lh .git

$ ls -lh .git
total 332K
drwxr-xr-x   2 nikhil nikhil 4.0K May 25 16:32 branches
-rw-r--r--   1 nikhil nikhil    2 Sep  1 12:25 COMMIT_EDITMSG
-rw-r--r--   1 nikhil nikhil 5.6K Sep  1 12:33 config
-rw-r--r--   1 nikhil nikhil   73 May 25 16:32 description
-rw-r--r--   1 nikhil nikhil   90 Sep  1 12:33 FETCH_HEAD
-rw-rw-r--   1 nikhil nikhil   23 Sep  1 12:33 HEAD
drwxr-xr-x   2 nikhil nikhil 4.0K Jun 11 15:25 hooks
-rw-r--r--   1 nikhil nikhil 229K Sep  1 12:34 index
-rw-r--r--   1 nikhil nikhil  44K Jun 11 08:56 INDEX
drwxr-xr-x   2 nikhil nikhil 4.0K Jun 11 15:25 info
drwxr-xr-x   3 nikhil nikhil 4.0K Jun 11 15:28 logs
drwxr-xr-x   8 nikhil nikhil 4.0K Aug 11 18:01 modules
drwxr-xr-x 260 nikhil nikhil 4.0K Jun 27 15:29 objects
-rw-rw-r--   1 nikhil nikhil   41 Sep  1 12:33 ORIG_HEAD
drwxr-xr-x   5 nikhil nikhil 4.0K Jun 11 15:25 refs

I identified the problem it was due to Anaconda in my .bashrc:

export PATH="$HOME/anaconda3/bin:$PATH"
if [ -f $HOME/anaconda3/etc/profile.d/conda.sh ]; then
    source $HOME/anaconda3/etc/profile.d/conda.sh
fi
conda activate

What should I do? When I comment this out git branch -a works.


回答1:


conda provides its own pager binary (not more or less, but pager). Using sudo clears your PATH -- so it fixes the problem not by virtue of changing permissions, but by virtue of preventing this faulty binary from being used at all.

To prevent this from having any undesired behaviors, move it out of the way:

mv ~/anaconda3/bin/pager{,.bad}


来源:https://stackoverflow.com/questions/52127324/why-do-i-need-root-privilege-to-do-git-branch-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!