0

I am facing a problem where a fork would be the perfect solution to, except it should not be possible to push changes to the upstream (not even though pull-requests). However, it must be possible to pull changes from the upstream once a while.

Is there a way I can block pushing to the upstream or are there other solutions I can apply?

Mirwais
  • 131
  • 1
  • 4
  • 18
  • It is possible to set the origin to an invalid URL, thus you cannot push to anything. This can be done through `git remote set-url --push origin no_push`. `no_push` is not a valid URL and bam! no pushing – mnestorov Feb 25 '20 at 13:58
  • maybe branch protection rules that restrict everything in combination with a CI that updates the repo could help... – dan1st Feb 25 '20 at 14:35

1 Answers1

0

The simplest thing is to just disable pushing to any remote. This can be achieved by setting your remote url to something invalid.

git remote set-url --push origin no_push

origin is your remote it will now reference no_push. Of course no_push is not a valid remote address, thus, it will fail every time you type git push.

Once you do want to push, just execute the same command, but specify a valid destination.

There are also other ways you can do that, like using git hooks as specified here.

mnestorov
  • 4,116
  • 2
  • 14
  • 24