Search code examples
githubgitlabfork

GitLab/GitHub: Why doesn't my fork *need* to be up-to-date?


To be clear: I am NOT asking how to keep my fork up-to-date. I am asking a very different question, and the answer seems to be independent of GitLab or Github.

I'm curious as to why my fork doesn't need to be kept up-to-date? I have forked a project, and I have a local clone of the project with two remotes ("thetango", my fork, and "upstream", the main project). I have noticed that I don't ever really need to update my fork on either GitLab or GitHub.

I would have thought that when I pushed to create a PR (GitHub) or an MR (GitLab) the first error I would have received is that my fork is out-of-date and needs to be fast-forwarded. That never happens, which confuses me.

What git magic does GitLab and Github implement so that my fork doesn't need to be updated? Am I misunderstanding what a fork is?


Solution

  • When you create a pull request between your fork of a repository and a branch in the main repository, you're essentially proposing a merge between a given branch in your repository and a given branch in the main repository. The only branches which matter in that case are those two.

    You may have other branches in your fork, such as the default branch and branches that include other work you're doing, but unless you're doing a pull request with one of them, how far ahead or behind they are from their corresponding branches in the main repository is irrelevant.

    Now, if the branch you're creating a pull request from is far behind the one you want to merge into in the main repository, then the chance of merge conflicts increases. Therefore, it's prudent to keep your local repository up to date with the main repository if you're going to be creating pull requests, so that when you push that branch to make a PR, the branch you push is not substantially out of date.

    One reason you may choose to keep your fork's main branch up to date is if you're doing independent development. For example, Git for Windows contains many Windows-specific patches which have not made it into mainline Git, so their repository is kept up to date because it's essentially an entire separate line of development.