다른 사용자 이름으로 GitHub에 어떻게 푸시합니까? 있습니다. Windows

친구와 내 컴퓨터를 공유하고 있습니다. Windows 7에서 git bash 쉘을 사용하여 GitHub에 푸시했습니다. 이제 우리는 해당 컴퓨터의 다른 프로젝트에 있으며 그녀의 계정으로 푸시해야합니다. 그러나 계속 내 사용자 이름을 사용하려고 시도하고 그녀의 저장소에 액세스 할 수 없다고 말합니다.

$ git push her_github_repository our_branch
ERROR: Permission to her_username/repository.git denied to my_username.
fatal: The remote end hung up unexpectedly



답변

다른 Windows 사용자를 사용하는 경우 SSH 키와 git 설정은 독립적입니다.

이것이 당신을위한 옵션이 아닌 경우, 친구는 SSH 키를 그녀의 Github 계정에 추가해야합니다.

이전 솔루션을 사용하면 자신을 계속 밀고 있지만 그녀의 저장소로 밀어 넣을 수 있습니다. 이것을 원하지 않고 같은 PC의 다른 폴더에서 작업 -g하려면 config 명령의 플래그를 제거하여 git를 사용하여 폴더 안에 로컬로 사용자 이름과 이메일을 설정할 수 있습니다 .

git config user.name her_username
git config user.email her_email

또는 https프로토콜 을 푸시 하면 암호 관리자를 사용하지 않는 한 Github에서 매번 사용자 이름 / 암호를 묻습니다.


답변

이것은 나를 위해 일했습니다. 사용자 이름과 암호를 묻는 메시지가 나타납니다.

git config --local credential.helper ""
git push origin master


답변

다른 계정을 사용하여 푸시 할 수 있습니다. 예를 들어, 계정이 .gitconfig에 저장된 A 이고 푸시하려는 리포지토리의 소유자 인 계정 B 를 사용 하려는 경우.

계정 B : B_user_name, B_password
SSH 링크의 예 : https://github.com/B_user_name/project.git

B 계정 의 푸시 는 다음 과 같습니다.

$ git push https://'B_user_name':'B_password'@github.com/B_user_name/project.git

.gitconfig에서 계정을 보려면

  1. $git config --global --list
  2. $git config --global -e (계정도 변경)

답변

사용자 지정을 사용하여 ssh 별칭을 설정하고 IdentityFile사용자 지정 me-github호스트 이름 을 사용하도록 원본을 다시 작성했습니다 .

#when prompted enter `id_rsa_user1` as filename
ssh-keygen -t rsa

# ~/.ssh/config
Host user1-github
HostName github.com
Port 22
User git
IdentityFile ~/.ssh/id_rsa_user1

#check original remote origin url
git remote -v
origin git@github.com:user1/my-repo.git

#change it to use your custom `user1-github` hostname
git remote rm origin
git remote add origin git@user1-github:user1/my-repo.git


답변

git@github.com:username/projectname.gitHTTPS URL 대신 SSH URL ( )을 사용하는 경우 $GIT_SSH_COMMAND환경 변수를 사용하여 다른 SSH 키를 임시로 지정할 수 있습니다 .

$ GIT_SSH_COMMAND="ssh -i different_private_key" git push

내가 알 수있는 한, SSH URL을 사용하여 GitHub는 사용자 이름, 키 만 신경 쓰지 않습니다. 사용자 계정이 저장소에 액세스 할 수 있고 해당 계정에 SSH 키가 있는 경우 (계정 의 SSH 키 페이지 참조) 해당 SSH 키를 사용하여 해당 리포지토리로 푸시하면 해당 푸시는 해당 사용자가 보낸 것으로 간주됩니다.


답변

git pushGit 을 실행 한 후 비밀번호를 요청 user하지만 로 비밀번호를 입력 new_user하려는 경우 git config remote.origin.url다음 을 사용할 수 있습니다 .

$ git push
user@my.host.com:either/branch/or/path's password:

이 시점에서를 사용 ^C하여 종료 git push하고 다음을 사용하여 as을 (를) 누릅니다 new_user.

$ git config remote.origin.url
user@my.host.com:either/branch/or/path

$ git config remote.origin.url new_user@my.host.com:either/branch/or/path

$ git push
new_user@my.host.com:either/branch/or/path's password:


답변

복제하는 동안 간단합니다 .git URL을 사용자 이름으로 사용하십시오. 커밋하는 동안 새 사용자 비밀번호를 묻습니다.

예 :

자식 복제 https : //username@github.com/username/reponame.git

자식 복제 https : //username@bitbucket.org/username/reponame.git