gitがスクリプトを実行したときにユーザー名を尋ねるのはなぜですか?

gitがスクリプトを実行したときにユーザー名を尋ねるのはなぜですか?

Pushこのスクリプトを実行するコマンドがあります。

FindGits |
{
    while read gitFolder; do
        parent=$(dirname $gitFolder);
        if [[ `git -C $parent status --porcelain` ]]; then
            echo;
            (
                echo $parent;
                git -C $parent status --porcelain
                git -C $parent add .
                git -C $parent commit -m "committed by script" 1>/dev/null 2>/dev/null
                if [[ $? == 128 ]]; then
                    git -C $parent commit -m "commited by script" 1>/dev/null 2>/dev/null
                    git -C $parent push
                    if [[ $? == 1 ]]; then
                        git -C $parent pull
                        git -C $parent push
                    fi
                else 
                    git -C $parent push
                    if [[ $? == 1 ]]; then
                        git -C $parent pull
                        git -C $parent push
                    fi
                fi
            ) &
        fi
    done
    wait
}

しかし、実行すると、gitはユーザー名を要求します。

「https://github.com」のユーザー名:

GitがGitHubにアクセスできることを確認するために行ったテストは次のとおりです。

  • ssh -T [email protected]=>成功
  • sudo -i+ =>成功ssh -T [email protected]
  • gitリポジトリに行き、いくつかのエントリを変更し、手動で+ commit + push =>成功を追加します。
  • 私は家に戻り、-C another_git_repo_path=>を使用して他のリポジトリで正常に追加+コミット+プッシュを実行しました.

もしそうなら、スクリプトの中で実行しても、なぜ動作しないのですか?

ベストアンサー1

gitリポジトリ(およびmakeなど)ssh操作に認証を使用する場合は、代わりに認証を使用するように各リポジトリを設定する必要があります。それ以外の場合、gitコマンドは引き続きユーザーとパスワードを要求します。pullpushsshhttps

ストレージ認証を変更するには、ssh次のコマンドを使用できます。

  1. git remote set-url origin [email protected]:UserName/Repo.git
  2. または、.git/configファイル内の対応する行を次のurl = https://github.com/ように変更できます。url = [email protected]:....
$> cat .git/config

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = [email protected]:UserName/Repo.git # edited line
        fetch = +refs/heads/*:refs/remotes/origin/*

おすすめ記事