【问题标题】:In Github, how do I figure out what remote branches I can push to?在 Github 中,我如何确定可以推送到哪些远程分支?
【发布时间】:2018-06-26 13:19:44
【问题描述】:

如何查看我可以推送到哪些分支?我刚刚接受了管理员的邀请,加入了一个 GitHub 项目,并切换到了我的代码所在的分支

localhost:myproject davea$ git checkout unit_tests_20180116
Switched to branch 'unit_tests_20180116'

但是当我尝试推送我的更改时,我收到一条错误消息,提示我无权推送到分支。

localhost:myproject davea$ git push origin master
Username for 'https://github.com': myusername
Password for 'https://myusername@github.com':
Counting objects: 54, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (48/48), done.
Writing objects: 100% (54/54), 101.02 KiB | 0 bytes/s, done.
Total 54 (delta 12), reused 0 (delta 0)
remote: Resolving deltas: 100% (12/12), completed with 5 local objects.
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: You're not authorized to push to this branch. Visit https://help.github.com/articles/about-protected-branches/ for more information.
To https://github.com/CaravanTransit/myproject.git
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/CaravanTransit/myproject.git'

如何确定我可以推送到哪些分支?

编辑: 以下是针对给定输出列出的内容。但是,虽然“master”出现在远程列表中,但我仍然无法推送到它。

localhost:myproject davea$ git remote show origin
* remote origin
  Fetch URL: https://github.com/CaravanTransit/myproject.git
  Push  URL: https://github.com/CaravanTransit/myproject.git
  HEAD branch: master
  Remote branches:
    adding-tests      tracked
    admin-panel-fixes tracked
    flexbox           tracked
    flexbox2          tracked
    master            tracked
    rename-to-caravan tracked
  Local branches configured for 'git pull':
    adding-tests merges with remote adding-tests
    master       merges with remote master
  Local refs configured for 'git push':
    adding-tests pushes to adding-tests (up to date)
    master       pushes to master       (fast-forwardable)

【问题讨论】:

  • 也许我错过了什么,但为什么会这样?这个问题是是否有人可以推送到现有的分支,我想知道我有资格推送到哪些分支。
  • 问题(如该答案中突出显示的那样)是您只能通过尝试推动某些东西并使其失败来知道 - 他们正在尝试“试运行”,但由于这没有改变,它实际上并没有测试写作能力。使用 git 可以通过多种方式控制授权 - 除非您知道那是什么(文件权限、网络服务器、提交挂钩等)并且有办法查询它,否则您不尝试就无法知道。
  • 好的,所以实际上没有办法按照我的要求去做。 (?) 听起来这是您应该提交的答案。
  • 您是否尝试查看错误消息告诉您查看的内容,关于受保护分支的 github 页面?

标签: github branch remote-access


【解决方案1】:

可以通过 git 以多种方式控制授权 - 除非你知道那是什么(文件权限、网络服务器、提交挂钩等)并且有办法查询它,否则你不能不尝试推送并查看它是否知道成功或失败。

--dry-run 实际上并不发送任何数据,所以这不是一个选项。

同样git remote 只显示潜在的遥控器 - 那里也没有授权测试。

所以恐怕没有办法检查这个!

【讨论】:

    【解决方案2】:

    git remote show <remote>(例如git remote show origin)向您显示您可以推送到哪些远程分支,以及also服务器上您尚未拥有或已从服务器中删除的远程分支。

    【讨论】:

    • 嗨,我编辑了我的问题以包含您列出的内容的输出。我误读了什么吗?远程分支列出“master”,但是当我尝试推送时,我得到了一个禁止的错误。
    • 不,我不认为你是。我开始认为此命令的输出并未显示文档中提到的“您可以推送到哪些远程分支”,而是您为哪些远程分支配置了本地跟踪分支。无论如何,您是否已与您的管理员联系,以查看他是否已授予您对此 repo 的贡献/协作权限?
    猜你喜欢
    • 2022-11-12
    • 1970-01-01
    • 2011-09-10
    • 2016-07-08
    • 2021-10-21
    • 2020-05-22
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多