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 저장소로 가서 몇 가지 항목을 변경하고 수동으로 + 커밋 + 푸시 => 성공을 추가합니다.
  • 나는 집으로 돌아가 -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/*

관련 정보