Part of my role at 2toLead is to help set guidance around best source management practices either internally or for our customers. One of the questions I get often is: Should I fork this repository or do something else with it?
It’s hard to get clear and simple guidance on the web so I thought I’d take a stab at it.
As we’re using Visual Studio Team Services, my examples and screenshots will be based on it, but it really applies to any git service like Github or internal git servers.
From my point of view, when you have an existing repository somewhere, you have the following options to move/copy it depending on your scenario:
Example of authoring a PR across repos.
Example of importing a repo
Now let’s say you landing on this article because the situation already got out of control. You have the “same” source base that got over multiple repositories, and not necessary on the recommended way, how do you fix that?
Before we begin let me say that this operation can be error prone, make you loose work, will induce a “service interruption” (even short) for your developers and this solution is provided with no warranty whatsoever. Also make sure all changes are committed and pushed before starting anything, for every developer accessing the repo.
You are facing two main cases:
Let’s say I have the current structure.
The second one being an import of the source one. Source didn’t get any updates since the import but the import did. And now I want to be able to propagate changes from importedRepo to the source one, without having to handle merges and multiple remotes locally.
First, fork the RepoSource repo into ProjectB/ForkedRepo
Then clone the ForkedRepo locally. After that run the following commands.
Make sure you set up the branch policies, builds definitions and release definitions are up to date. Even run a diff tool on your local machine, branch per branch, between the two repositories folders and you’re good to go!
For the other developers on the team, simply run these set of commands to re-map to the new forked repository.
Please make it easier to move Git repositories between team projects keeping the fork link and everything.
I hope that post helped bring a bit of clarity on the best practices as well as it helped some of you fix the situation.