Search code examples
gitgithubgit-remote

Git - develop on own remote and publish on github


I have the following situation:

I am developing something with some other people on our own (private) server. This is useful to keep the files backed up and available. However, I would also like to host them on github.

Is there a way I can push and pull from my own server, but push (and only push) to github? I would like to disable fetching from github entirely because it doesn't make much sense. Essentially, we would like to use github as a way to publish our application so others can clone it, but still work entirely on our own infrastructure.

I added the remote with git remote add github <url> and added a push URL for it using git remote set-url --add --push github <url>.

Now I would need to remove the fetch URL but when I do git remote set-url github --delete <url>, it says fatal: Will not delete all non-push URLs.

This is obviously intended behaviour, but I would still like to work around it (or find a good solution to my problem). Can I just delete the fetch URL in my config or does that break anything in the long run? Is there an entirely different solution to my problem?

I've read through Git - Pushing code to two remotes, but the solution presented there adds a second push URL, instead of a new remote. As far as I understand, this is not exactly what I would want, as the manual for git remote says:

Note that the push URL and the fetch URL, even though they can be set differently, must still refer to the same place. What you pushed to the push URL should be what you would see if you immediately fetched from the fetch URL. If you are trying to fetch from one place (e.g. your upstream) and push to another (e.g. your publishing repository), use two separate remotes.

...so I should rather use two repos, right? Or am I understanding this wrong?


Solution

  • For my answer, I recommend rethinking the purpose of pushing to Github. I don't think there is any reason to remove the fetch.

    Reasoning related to Github

    1. Github limits authority to push to the repo to only those people you give access to. So what changes are you expecting to happen on the remote that you could accidentally pull down anyway?

    2. If anyone wants to update your Github code, they will fork it, and at that point they can completely ignore your changes if they choose. The only way their changes can affect your publish repo is if they submit a pull request to you and you or someone you have given authority accepts it and merges the changes into the repo. If this happens, I assume you will need and want to pull that change down into your internal repo, because it was a bug fix or enhancement that makes sense/adds value across the board (make sure you have the right licensing and contributor agreements in place if you do this).

    In other words, I don't see there ever being any changes on that repo that are something you don't ultimately want to use internally.

    Reasoning related to internal workflow

    1. If you accidentally try to pull down Github when it's behind your current repo, git will warn you about it and not change your branch references - you would need to do a force to cause any issues - and even then, you can just fix it by pulling from your updated internal repo. You'd have to force fetch from Github, then force push internally, to really mess things up, and then anyone else on the team could still fix it from their local repo!

    2. Not everyone on the team needs to even add Github as a remote - only the person(s) responsible for actually pushing to Github. So general training should not be an issue here.

    I guess I don't see the need to solve this problem.