0

I've forked a private repository hosted on Github and intend to do all my work in my fork and submit pull requests from my fork to the main repository.

I've configured my remotes so origin points to my fork, and upstream points to the main repository (so I can keep my fork's master branch in sync with the main repo).

I'd like to maintain my ability to have full access to the repository on Github, but as a safety precaution, want to disable my ability to push to origin directly from my local machine.

Is this possible with a configuration to my remotes on my local machine?

ehed
  • 804
  • 1
  • 8
  • 18
  • 1
    possible duplicate of [Git: Set up a fetch-only remote?](http://stackoverflow.com/questions/7556155/git-set-up-a-fetch-only-remote) – Kristján Jul 10 '15 at 15:55

2 Answers2

2

I'd like to maintain my ability to have full access to the repository on Github, but as a safety precaution, want to disable my ability to push to origin directly from my local machine.

Just configure your remote using the git:// protocol, which does not permit updates. E.g., if I have:

$ git remote -v
origin  git@github.com:larsks/py-st7565.git (fetch)
origin  git@github.com:larsks/py-st7565.git (push)

I can run:

$ git remote set-url --push origin git://github.com/larsks/py-st7565.git

And if I try git push I get:

$ git push
fatal: remote error: 
  You can't push to git://github.com/larsks/py-st7565.git
  Use https://github.com/larsks/py-st7565.git
ehed
  • 804
  • 1
  • 8
  • 18
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Hm, because it is a private repository, though, it's invisible when I make that change: ```$ git pull upstream master fatal: remote error: Repository not found.``` – ehed Jul 10 '15 at 17:18
  • You can just the `--push` URL, as @ehed suggested in his edit (ehed: better to leave a comment instead of editing someone's answer in a way that changes the answer). And of course, in this case there's no need to even set it to a valid URL. – larsks Jul 10 '15 at 17:40
1

OK, the solution was to do what larsks said but with the --push flag set:

git remote set-url --push origin git://github.com/larsks/py-st7565.git

That keeps the fetch remote intact.

Thank you!

ehed
  • 804
  • 1
  • 8
  • 18