如何编写.netrc为两个帐户跳过键入密码什么时候git推?

时间:2018-06-09 01:51:43

标签: git passwords

在执行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 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)

2 个答案:

答案 0 :(得分:2)

正确的语法会重复机器 你可以在不同的行上写下两个条目:

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 :(得分:0)

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

$dot-list: 1 2 3 4 5;

.dot-animation {
    display: block;
    span {
        display: inline-block;
        margin-top: 10px;
        height: 20px;
        width: 20px;
        border-radius: 50%;
        &:not(:first-child) { margin-left: 30px; }
    }
    @each $current-dot in $dot-list {
        $i: index($dot-list, $current-dot);
        $t: $i * -0.787;
        span:nth-child(#{$i}) {
            background: white;
            border: 5px solid #48c0c0;
            animation: move 1s ease-in-out (#{$t}s) infinite alternate;
        }
    }
}

@keyframes move {
    from { transform: translateY(0px); }
    to { transform: translateY(60px); }
}

2.添加git push的来源。

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

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