Is there a way to dry run a git push
to know whether the user has permissions to actually create a new remote branch? I'd like to be able to verify that all is good in regards to permissions for a bunch of repos where the user will attempt to create new branches before they are actually created so that I can dry run the full execution before actually doing it.
-
1Check [this question](http://stackoverflow.com/q/3636914/1860929) and [this answer](http://stackoverflow.com/a/3636939/1860929) on it. – Anshul Goyal Aug 20 '14 at 14:25
-
same question, newer answer: http://stackoverflow.com/a/29801749/1875965 – Sandra Jul 25 '16 at 14:07
-
A github only answer: https://stackoverflow.com/a/65683358/99717 – Hawkeye Parker Mar 25 '22 at 23:27
3 Answers
Shawn Pierce wrote the following about git push --dry-run
:
A
--dry-run
doesn't send the commands the client would use from client to server, so the server can't tell the client if it would accept them or not. The entire--dry-run
thing is client side only.
(my emphasis)
So, if there is a way to check whether one has write permissions to a remote, git push --dry-run
is definitely not it.

- 60,866
- 25
- 183
- 186
-
4Just a comment, in case anyone else was slightly misled by the above, as I was. git push --dry-run does everything except actually sending the updates, in particular, it does check to see whether the remote has changes that you don't have locally (as I have just confirmed by experiment). So it is a bit misleading to say it is a client side only operation - it does access the remote, but it doesn't try to update it. – Rob Arthan Nov 10 '22 at 21:27
Posting as an answer on the test I did where I don't think it works in my scenario. I'm creating a branch form another one without further changes
git clone ....
git checkout master
git branch -f test master
git push --dry-run origin test
and it passed even though I have zero push permissions on this server/repo combo
To ssh://<server>/repo
* [new branch] test -> test
Pushing without dry-run hits the error condition I was expecting
git push origin test
Total 0 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://<server>/repo
! [remote rejected] test -> test (can not create new references)
error: failed to push some refs to 'ssh://<server>/repo'

- 3,324
- 2
- 27
- 31
In the git push
docs @ https://git-scm.com/docs/git-push --dry-run apears as an option:
git push [--all | --mirror | --tags] [--follow-tags]
[--atomic] [-n | --dry-run ] ... (more flags)
It usually means that the commands are handled as usual by the server, except that the data is not modified, that is, nothing is changed.
It is useful for testing critical commands, because the output logged by the server is (almost) equal to that of a "wet" run.

- 2,149
- 25
- 26

- 2,293
- 23
- 18