Maintaining multiple branches of the same base project in VS

I have looked through the site but I could not find an answer that completely covers mine, so please excuse me in advance if I missed this.

I inherited a VB.NET project that had no version control (it started out as a hobbyist long-gone developer project and no one ever bothered to stick it in after that), and at the suggestion of a friend, I thought about using Git for source control.

The project is a niche product that is customized and sold according to customer specifications, so a problem arises: even if 95% of the code is the same for all customers, sometimes up to 10% of the code is changed and adapted for each customer, by changing or adding lines to existing functions. sometimes adding whole blocks of code, but there is no generality in changes between different clients (a function changed in one cannot be changed in another).

To complicate matters, due to service contracts, updates made in the base application have to be replicated to branch clients if they want them, and sometimes the changes we make for a specific client are good enough for us to put in the base application and replicate them to other clients, but keeping the settings for each client!

So, with my little knowledge of Git, I figured it would be like this:

          (customer 1)
         C1-----
(main)  /
A------B------D
        \
         \ (customer 2)
         C2-----
        \
         \ (customer 3)      
         C3-----

      

... but I don't see how this would work after this:

  • Can I merge SOME changes from client's branches into mainline WITHOUT merging others that are only useful to that client?
  • Can I merge SOME changes from the main trunk into each client branch without losing any of the settings in those branches?
  • Can I "label" certain lines of code so they don't get merged / executed?
  • Three or more developers will be working on this, each on their own machine, but pushing changes to the company's repository to sync. What are the consequences of this process?
  • Currently , each client has a separate folder and separate project files with all the source codes. ... How does the import process put these folders into Git?
  • This should all be done with Visual Studio, with Gitextensions and a Git source provider for VS. Is this supported or should it be done with the console?

Thanks and sorry again if it overlaps with another answer.

+3


source to share


1 answer


I'm relatively new to git and I usually use PoshGit for all my operations, so while I may not be able to help you with everything, I hope I can help with some things:

  • Can I merge SOME changes from client's branches into mainline WITHOUT merging others that are only useful to that client?
  • Can I merge SOME changes from the main trunk into each client branch without losing any of the settings in those branches?

From what I understand, both of these operations can be achieved with git cherry picking , which allows you to select a specific commit from one branch and add it to the other without merging branches together.

For example, if you want to add the changes you made to the customer1 repository to customer2:

First you get the commit hash id from customer 1 that you want to insert into customer2

git checkout customer1Branch
git log 

commit 2e8c40025939e8cf41dec70f213da75aa462184b
Author: xxxxxxx
Date: xxxxxx

This made a change that you want...

      

Then you copy the first few characters of the hash you want cherry pick , go to client 2 branch and cherry pick to branch.

git checkout customer2Branch
git cherry-pick 2e8c40025939e8c

      

Now, if you do git log

, you will see that your cherry fence is at the top. A similar tutorial can be found here ( http://nathanhoad.net/how-to-cherry-pick-changes-with-git )

  • Can I "label" certain lines of code so they don't get merged / executed?

You can find help on a similar question and answer here:

Commit only part of a file in Git

  • Three or more developers will be working on this, each on their own machine, but pushing changes to the company's repository to sync. What are the consequences of this process?

Since git is a fully distributed VCS, every developer on your team will effectively have a complete clone of the central repo on their machine (complete with the complete history of that repo). This means that history log queries and other queries (such as figuring out who did what) do not need to go through a central server, but can be done privately and offline by each developer.

Likewise, the changes every developer makes will be available to all of you (for example, all new branches will be available), but sometimes it can be tricky to work with the same features if you are not quite using pre-git.

As always, it is a good idea to do early and often, it will reduce the stress that you are likely to face when changes occur. you should also establish some structure for when pushes are made, especially if you rely on each other's work to proceed.

Another idea you can try is to have one person in charge of the repo and make them merge changes and patches to help you coordinate your efforts.

  • Currently, each client has a separate folder and separate project files with all the source code. How will the process be imported to put these folders in Git?


EDIT

Thanks for clarifying what you mean by this question. You can extend a similar approach adapted from the answer given here: How do I create a remote git branch?

Create a new mainline branch for your BASE project and push it to the remote repository.

cd baseProjectDirectory # navigate to your main project directory
git init # git initialize the dir
git add . # recursively add all files in directory to git repo
git remote add <remote-branch-name> <remote-url> # Add the url to your remote directory to your git repo
git commit -m "Initial commit of base project"
git push <remote-branch-name> <local-branch-name>

      

This will install your base project in a remote repository called remote-branch-name

under the named branch local-branch-name

.

You can then move on to other projects and repeat these steps, pushing your repositories to different branches on the same remote, using the new local branch names, i.e. instead of using local-branch-name

when creating a branch, just use the new branch name likegit checkout -b new-local-branch-name

so for example your basic push project (last line of code):

git push clientproject base

      

Where "clientproject" is the name of your remote and "base" is the name of your local branch, you can simply change the line:

git checkout -b client1 # Creates new branch named client1
git branch -d base # Deletes base branch
git push clientproject client1

      

Note that while it is not strictly necessary to delete the "base" branch to continue, it keeps your repository clean and is therefore considered good practice. Don't worry about losing anything, but your entire git history from the base will be copied to client1 on checkout.

Also note that since your situation requires you to do this from different directories, you will probably delete the branch named "master" and not "base".

Clicking this button will maintain client1 on the clientproject remote machine, but will push the project to a new branch named client1, which will create its own history.

The same steps can be used for other projects. If I've lost you anywhere along the way, I suggest reading the link above (it's much more eloquent than me).

  • This should all be done with Visual Studio, with Gitextensions and a git source provider for VS. Is this supported or does it need to be done with the console?

I haven't used VS with Git yet, but my guess is that most if not all of these operations will be supported as they are native git commands.

Hope it helps.

0


source







All Articles