Can I mark a GIT remote as read only? [duplicate]

I have read/write access to a repo on GitHub. I have a local clone of that repo. I'd like to be able to pull changes from that remote, but I should never push changes to it.

Is there a way I can mark the remote as read-only so I never accidentally type in the wrong command and push to it?


Solution 1:

You could shut off default pushes via

git config push.default nothing

or for stronger protection on a specific remote you could break pushes to that remote entirely by e.g.

git config remote.origin.pushurl "you really didn't want to do that"

Solution 2:

git remote set-url origin --push "hey, stop pushing"

Note that the following removes an explicitly configured push URL, but then pushes will use the fetch URL, so not what you want:

git remote set-url origin --delete --push ".*"