48

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?

Marc Hughes
  • 5,808
  • 3
  • 36
  • 46

2 Answers2

67

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"
jthill
  • 55,082
  • 5
  • 77
  • 137
  • 3
    "git config remote.origin.pushurl "you really didn't want to do that"" -- I love that idea. Thanks. Turning off default pushes wouldn't be ideal since I do want to push to other locations. – Marc Hughes Apr 24 '12 at 18:41
  • git config remote.origin.pushurl "you really didn't want to do that" has blocked all the pushes in all branch. What to do? How can you reove read only – Rajesh Kumar Jul 04 '14 at 06:09
  • @RajeshKumar just delete the config item. – jthill Jul 04 '14 at 07:18
21
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 ".*"
Scott Buchanan
  • 1,163
  • 1
  • 11
  • 28
yoyo
  • 8,310
  • 4
  • 56
  • 50