Monday, July 4, 2016

Git Tutorial 2-- Simulate two developers



For developers, regardless of SVN or Git, he would need similar things:

  1. A local working directory where he can work on his stuff undisturbed for a certain period
  2. He needs to constantly look out for changes in the remote repository in case the files he is working on has been changed by others
  3. he would want to commit his changes to the remote repository if:

a)      the changes are complete
b)      If there are too many changes, he may want to commit the changes that he is fairly certain (in his best knowledge) that is not going to be changed or not going to be used by others soon or not going to break something; because if he changes something which is picked by someone else, if he is later going to change them again, he will impact others. 

I’ve written several scripts to simulate two developers using Git. To make things easier, dev1 is the luck one, he always gets to commit his changes earlier. dev2 is the one who we feel sympathy for, as he is the one always runs into conflicts. We will see how dev2 uses different approaches to handle his daily work.

Every script starts out the same: it will create an empty repository in Github, and create two local repositories for the two developers. Afterwards, it will act as two developers, update files and commit the changes to the Github repository. In the process, it will create conflicts for dev2. After each significant step, the script will stop and ask you to check your local repository, so you can understand what each git command does:


To understand what each git command does, I find it is best to use a UI, I recommend using a free tool SourceTree. Add the local repository created by the script into SourceTree:


So now it is clear what the script does and how you should use it. Let us start the day for the two developers.

 Day1

dev1 checks out a local branch t1, and commits two changes to it:
dev2 does a similar thing, he checks out a local branch t2, and commits two changes to it:

Why do these developers want to check out a local branch instead of working directly on the local master branch?

Because the remote branch will be constantly changed, the local master branch is supposed to be a mirror of the remote master branch, if the local master branch is to be synced up with the remote master branch, the developers’ work will be constantly interrupted. Developers will be working on their local branch, sync up their local master with the remote master, compare their local branch with the local master branch, and decide to syncup their local branch with the local master branch when they feel need to. 

So far, everything is fine, there is no drama. Drama comes later.

No comments:

Post a Comment