如何为两个帐户编写 .netrc 以跳过输入密码何时进行 git push?



执行命令时跳过输入密码很简单git psuh

vim  .netrc
machine github.com
login user1
password  pass-user1

如何为两个帐户编写 .netrc 以跳过输入密码何时进行 git push?

按如下方式编写 .netrc 是没有用的。

vim  .netrc
machine github.com
login user1
password  pass-user1
login user2
password  pass-user2

根据 VonC 编辑 .netrc,如下所示。

machine github.com login user1 password  pass-user1
machine github.com login user2 password  pass-user2 

git 推送的奇怪错误。

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)

正确的语法会重复机器。
您可以将这两个条目写在单独的行上:

machine github.com login user1 password  pass-user1
machine github.com login user2 password  pass-user2

但是,请确保您的源远程 URL 指定了以下两个用户之一:

如果已定义origin遥控器,请将其更改为:

git remote set-up origin https://user2@github.com/user2/arepo.git

但是,如果您使用的是新的本地存储库,没有任何origin,请添加它:

git remote add origin https://user2@github.com/user2/arepo.git

1.在 .netrc 中为两个帐户设置。

machine github.com login user1 password  pass-user1
machine github.com login user2 password  pass-user2

2.添加 git 推送的源。

git remote add origin   https://user2@github.com/user2/arepo.git

git remote set-up origin https://user2@github.com/user2/arepo.git

最新更新