1

How do I see what branches I have access to push to? I just accepted an invitation from our admin to a GitHub project and switched to the branch where my code was

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

but when I try and push my changes, I get an error saying I'm not authorized to push to the branch.

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'

How do I figure out what branches I am allowed to push to?

Edit: Here's what's listed in response to the output given. However, although "master" appears in the remote list, I'm still not able to push to it.

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)
jthill
  • 55,082
  • 5
  • 77
  • 137
Dave
  • 15,639
  • 133
  • 442
  • 830
  • 1
    Possible duplicate of [How can one dry run a git push to check whether one has write permissions to a remote?](https://stackoverflow.com/questions/25403573/how-can-one-dry-run-a-git-push-to-check-whether-one-has-write-permissions-to-a-r) – match Jan 17 '18 at 16:02
  • Maybe I missed something but why is this the same? That quesiton is whether someone can push to an existing branch and I'd like to know which branches I'm eligible to push to. – Dave Jan 17 '18 at 16:15
  • The problem (as highlighted in that answer) is that you can only know by trying to push something and have it fail - they were trying a 'dry-run' but as this makes no changes, it doesn't actually test write ability. Authorization can be controlled in multiple ways with git - unless you know what that is (file permissions, webserver, commit hook etc) and have a way to query it, you can't know without trying. – match Jan 17 '18 at 16:31
  • Ok, so there is actually no way to do what I'm asking. (?) Sounds like that's an answer you should submit. – Dave Jan 17 '18 at 17:12
  • Did you try looking at what the error messages told you to look at, the github page about protected branches? – jthill Jan 17 '18 at 18:46
  • Git doesn't give you this ability - you'll need to ask your GitHub administrator. The best you can do is view the branch list in the GitHub UI, which will show padlock icons next to protected branches. However, this doesn't tell you to what degree they are "protected". – Edmund Dipple Jan 18 '18 at 09:29

2 Answers2

1

Authorization can be controlled in multiple ways with git - unless you know what that is (file permissions, webserver, commit hook etc) and have a way to query it, you can't know without trying a push and seeing if it succeeds or fails.

--dry-run doesn't actually send any data, so that isn't an option.

Equally git remote only shows potential remotes - there's no authorization testing there either.

So theres no way to check this I'm afraid!

match
  • 10,388
  • 3
  • 23
  • 41
-1

git remote show <remote> (e.g. git remote show origin) shows you which remote branches you can push to and also which remote branches on the server you don’t yet have or have been removed from the server.

kingJulian
  • 5,601
  • 5
  • 17
  • 30
  • Hi, I edited my question to include the output of what you list. Am I misreading something? The remote branches list "master" but when I try to push to that I get a forbidden error. – Dave Jan 17 '18 at 17:37
  • No, I don't think you are. I am starting to think that the output of this command doesn't show "which remote branches you can push to" as mentioned in the documentation but rather for which remote branches you have configured local tracking branches for. In any case, have you checked in with your admin to see if he has granted you contribution/collaboration rights for this repo? – kingJulian Jan 17 '18 at 18:09