git 无法为用户创建 gitconfig 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17908386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:50:34  来源:igfitidea点击:

Unable to create gitconfig file for user

git

提问by patriques

I have installed git as root on my Linux (debian) system before I had created my user. After I created the user I try to run the command (as the new user):

在创建用户之前,我已经在 Linux (debian) 系统上以 root 身份安装了 git。创建用户后,我尝试运行命令(作为新用户):

git config --global user.name "myusername" 

But I get the error:

但我收到错误:

error: could not lock config file /home/<username>/.gitconfig: Permission denied

When I type

当我打字

git config --global --edit

It starts my editor with the path /home/<username>/.gitconfig. I think this is really weird. I have tried to create the .gitconfig file by creating it as sudoand then move the .gitconfig file from /root/.gitconfigto /home/<username>/.gitconfigand lastly chownit to my user, but that does not work either. Please help me..

它以 path 启动我的编辑器/home/<username>/.gitconfig。我觉得这真的很奇怪。我试图通过将其创建为sudo来创建 .gitconfig 文件,然后将 .gitconfig 文件从/root/.gitconfigto移动到/home/<username>/.gitconfig最后将其chown给我的用户,但这也不起作用。请帮我..



EDIT: The problem had to do with user permissions on the home directory of the user. I just ran:

编辑:问题与用户主目录的用户权限有关。我刚跑:

sudo chown username:username /home/username

And then it worked as usal.

然后它照常工作。

回答by sjas

Before you go borderline insane, just edit/insert the username by hand inside the .gitconfig? Open it up with the editor of your choice and go ahead:

在您疯狂之前,只需在.gitconfig? 使用您选择的编辑器打开它并继续:

gitconfig excerpt from me:

gitconfig 摘自我:

[user]
        name = myusername
        email = [email protected]
[color]
        branch = on
        diff = on
        interactive = on
        status = on

...

The user.namefrom the commandline is the [user]+ name =combo in the config.
nameis just indented with a tab.

username从命令行是配置中的[user]+name =组合。
name只是缩进了一个制表符。

回答by Dan Barber

Install git

安装 git

vagrant@precise32:~$ sudo apt-get install git

....Set up your user

....设置您的用户

vagrant@precise32:/$ sudo useradd -m yourusername
vagrant@precise32:/$ sudo passwd yourusername
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
vagrant@precise32:/$ su - yourusername
Password: 
$ ls
$ pwd
/home/yourusername

...Configure git

...配置git

$ git config --global user.name "yourusername"
$ ls -a
.  ..  .bash_logout  .bashrc  .gitconfig  .profile
$ cat .gitconfig
[user]
    name = yourusername

回答by Sukhmeet Singh

try this if this works for you

试试这个,如果这对你有用

mkdir ~/.git 
git config --global user.name= <name>