远程拒绝推送到主分支:master(权限被拒绝)。

13

我克隆了: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'

这是本地代码库的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

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

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


你的 Github 账号是 vy2014 吗? - tkausl
是的,我在同一台计算机上使用了2个GitHub帐户。 - Raphaël Colantonio
1
也许这可以帮助你:https://dev59.com/XV0Z5IYBdhLWcg3whQsj - tkausl
根据我的经验,我需要请求仓库所有者将我添加到协作列表中。一旦完成,它就开始正常工作了。 - Abhishek Singh
3个回答

22

输入命令:

git config --global --edit
在文件末尾添加以下配置行:
[credential]
  helper = osxkeychain
  useHttpPath = true

这也解决了我的问题,谢谢!在这些说明对我无效后,我找到了这个链接:https://help.github.com/articles/updating-credentials-from-the-osx-keychain/ - Titus
很好,它让 git 提示输入用户名和密码,否则是不会提示的。 - Avatar Girase

7

我正在使用Linux,因此回答中的osxkeychain对我没有帮助。

在启用了GitHub的两步验证之后,我遇到了同样的错误。

解决方案如下:

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

可以按照以下方式完成:

git remote set-url origin git@github.com:username/your-repository.git

1
作为补充,我使用的是 Fedora 系统,并遇到了相同的错误。
通过输入 git config --global --edit 命令,以下内容被列出。删除它们后,一切正常运行。
  [credential]
  helper = store

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接