Creating multiple git forks using upstream branches

Working with Git is... complex. It's not that it's from another world, and the complexity is probably worth it considering the crazy things it allows you to do, but sometimes it's just mind-bloggingly complex to understand how to do things right. Recently, we've had to manage a series of projects with changes that cannot be applied directly to our original Git repository on Github, so we decided, after giving it some thought, to make several forks of the project (instead of branches), to manage more clearly permissions and the real intentions behind each of the forks. This would allow us a few important things:
  • define precisely permissions based on the repository
  • use the repository to pull changes directly on our servers
  • have some level of local customization on each server, using local commits (and subsequent merges)
  • keep easy track of the changes that have been made on requests from some of our "customers" (they're not necessarily commercial customers - sometimes they're just users who decided to go crazy and show us what they can do, and we want to show that in public)
To do that, we need to fork our project (chamilo/chamilo-lms) several times over. So the first problem is: you cannot fork the same project twice with the same user. Adrian Short (@adrianshort) kind of solved that issue in his blog article, saying that you can just do the fork manually, creating an empty repo on Github and filling it with a copy of the main repo, then adding the origin remote manually. Even though that works, the Github page (starting from the second fork with the same user) will *not* indicate it has been forked from chamilo/chamilo-lms: you'll have to issue the git remote -v command to see that the upstream is correct. The second problem is that the article doesn't dive into the details of branch-level forks, so this article intends to solve that particular missing detail, and in that respect, the Github help is definitely useful. Check Syncing a fork help page if you want the crunchy details. To make it short, there are 3 issues here:
  • fetching the branches from the original repo (upstream)
  • getting the desired branch to be checked out into your local repo
  • defining that, from now on, you want to work on your repo as a fork of that specific branch in upstream (to be able to sync with it later on)
The complete procedure then, considering my personal account (ywarnier) and the original chamilo/chamilo-lms project on Github, with the intention to work on branch 1.9.x, would look like this: git clone git@github.com:chamilo/chamilo-lms git remote -v git remote rename origin upstream (here you have to create the "chamilo-lms-fork1" repo by hand in your Git account) git remote add origin git@github.com:ywarnier/chamilo-lms-fork1.git git remote -v git push -u origin master git branch -va git fetch upstream git branch -va git checkout --track remotes/upstream/1.9.x This should get you up and kicking with your multiple forks in a relatively short time, hopefully!