在执行git psuh命令时跳过输入密码很简单。
vim .netrc
machine github.com
login user1
password pass-user1
Run Code Online (Sandbox Code Playgroud)
如何为两个帐户编写 .netrc 以在 git push 时跳过输入密码?
.netrc 如下写是没有用的。
vim .netrc
machine github.com
login user1
password pass-user1
login user2
password pass-user2
Run Code Online (Sandbox Code Playgroud)
根据 VonC 编辑 .netrc 如下。
machine github.com login user1 password pass-user1
machine github.com login user2 password pass-user2
Run Code Online (Sandbox Code Playgroud)
git push 的奇怪错误。
git push -u origin master -f
remote: Permission to user2/test.git denied to user1.
fatal: unable to access 'https://github.com/user2/test/': The requested URL returned error: 403
git remote -v
origin https://github.com/user2/test (fetch)
origin https://github.com/user2/test (push)
Run Code Online (Sandbox Code Playgroud)
正确的语法会重复机器。
您可以将两个条目写在单独的行上:
machine github.com login user1 password pass-user1
machine github.com login user2 password pass-user2
Run Code Online (Sandbox Code Playgroud)
但是,请确保您的源远程 URL 指定了两个用户之一:
如果你已经有一个origin远程定义,更改:
git remote set-up origin https://user2@github.com/user2/arepo.git
Run Code Online (Sandbox Code Playgroud)
但是,如果您使用的是新的本地存储库,没有任何origin,请添加:
git remote add origin https://user2@github.com/user2/arepo.git
Run Code Online (Sandbox Code Playgroud)