1)如果您试图通过https将本地repo连接到远程。如果是这种情况,那么以下命令应该为您解决该问题:
$ git remote -v
origin https://github.com/private-repo.git (fetch)
origin https://github.com/private-repo.git (push)
$ git remote rm origin
$ git remote add origin git@github.com:private-repo.git
$ git remote -v
origin git@github.com:private-repo.git (fetch)
origin git@github.com:private-repo.git (push)
2)移除远程原点
git remote rm origin
重新添加源站,但使用您的用户名和pwd,在此pvt repo上具有写入权限
git remote add origin https://USERNAME:PASSWORD@github.com/username/reponame.git
3)您已经配置了ssh密钥
#check current github account
ssh -T git@github.com
#ensure the correct ssh key used with github
ssh-agent -s
ssh-add ~/.ssh/YOUR-GITHUB-KEY
#re-add the origin
git remote add origin git@github.com:YOUR-USER/YOUR-REPO.GIT
git push -u origin master
4)您可能需要尝试在repo url中包含我的用户名和密码来解决它:
git clone https://myusername:mypassword@github.com/path_to/myRepo.git
注:
这个详细的步骤可能会帮助您,并且正在考虑您没有在GitHub中创建回购。
在GitHub上创建新的存储库。为了避免错误,不要用自述文件、许可证或gitignore文件初始化新的存储库。您可以在项目被推送到GitHub之后添加这些文件。
git init
git add .
git commit -m "First commit"
# Sets the new remote
git remote -v
# Verifies the new remote URL
git push origin master
如果存在Github回购,则执行以下步骤。
cd existing_repo
git remote rename origin old-origin
git remote add origin <url>
git push -u origin --all
git push -u origin --tags