![远程拒绝]主 - >主(权限被拒绝)

nhu*_*uvy 5 git github

我克隆:https://github.com/vy2014/git_lesson.git

然后我做了一些更改,尝试按命令推送到远程服务器git push,但是错误:

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 273 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local objects.
To https://github.com/vy2014/git_lesson.git
 ! [remote rejected] master -> master (permission denied)
error: failed to push some refs to 'https://github.com/vy2014/git_lesson.git'
Run Code Online (Sandbox Code Playgroud)

这是本地存储库中的git配置(命令后返回的内容) git config --list

core.excludesfile=~/.gitignore
core.legacyheaders=false
core.quotepath=false
core.pager=less
mergetool.keepbackup=true
push.default=simple
color.ui=auto
color.interactive=auto
repack.usedeltabaseoffset=true
alias.s=status
alias.a=!git add . && git status
alias.au=!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.c=commit
alias.cm=commit -m
alias.ca=commit --amend
alias.ac=!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.d=diff
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\     => \2/' | sort
include.path=~/.gitcinclude
include.path=.githubconfig
include.path=.gitcredential
diff.exif.textconv=exif
credential.helper=osxkeychain
filter.lfs.clean=git-lfs clean %f
filter.lfs.smudge=git-lfs smudge %f
filter.lfs.required=true
color.ui=true
core.autocrlf=input
push.default=simple
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/vy2014/git_lesson.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
Run Code Online (Sandbox Code Playgroud)

我如何将文件推送到GitHub服务器?

(我在macOS Sierra 10.12上使用Git版本2.10.0)

nhu*_*uvy 12

键入命令:

git config --global --edit
Run Code Online (Sandbox Code Playgroud)

在文件末尾添加以下配置行:

[credential]
  helper = osxkeychain
  useHttpPath = true
Run Code Online (Sandbox Code Playgroud)


chi*_*kiy 7

我使用的是 Linux,这就是为什么回答对osxkeychain我没有帮助。

在 github 中启用 2FA 后我遇到了同样的错误

接下来的解决方案是:

  1. 生成新的 SSH 密钥并将其添加到 ssh-agent
  2. 将新的 SSH 密钥添加到 GitHub 帐户
  3. 将存储库的远程从更改 https://github.com/username/your-repository.gitgit@github.com:username/your-repository.git

可以用下一种方式完成

git remote set-url origin git@github.com:username/your-repository.git
Run Code Online (Sandbox Code Playgroud)