In Github, how do I figure out what remote branches I can push to?

Refresh

April 2019

Views

95 time

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://[email protected]':
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)

2 answers

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!

-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.