There is a standard way for doing this. Use git normally and this never happens.
Git is distributed version control system. When you fetch
from a repository (A
) into yours, you get a copy of the branches in that repository in yours, named A/branch_name
. You probably have seen this when doing git merge origin/master
for example. Changing the branch on the remote repository doesn't affect your local copy of it until your next fetch
, which happens whenever you decide.
So, what does this mean? Let's think of the following actions:
A
has branchbranch
.- You fetch from
A
in your repository and merge into your localbranch
. - You start your lengthy process on your local repository.
- Meanwhile, somebody else pushes to
branch
onA
. - You still do your lengthy process on your local repository without ever knowing about step 4.
- You try to push back your merge.
So at this point, you know that everything works on your local repository. However, when you try to push, you can't. Some observations:
- At step 4, whoever pushed to
A
did the same lengthy tests in parallel with you, but finished earlier. So he made sure that everything withbranch
onA
is ok. - If the other person had locked
A
as read-only, you wouldn't know until step 6, since you were reading from the repository anyway. So making the repo read-only wouldn't change anything.
Now what this means for you is that you have to repeat the above steps. So you have to fetch
again, merge
again and run your lengthy tests again. But this is ok and is usually what is done, however not as bad as you might think.
There are two possibilities:
- The other person was working on something you had been working on yourself (unlikely).
- The other person was working on something totally unrelated (likely).
In the second case, there is no problem. The merge would go smooth and you don't need to repeat the lengthy tests since the tests for each subsystem are separate (they are, right?!). Perhaps you would run the tests on the complete integration.
In the second case, there would be merge conflicts, which means more work for merge conflicts and running tests again. But that merge conflict would sooner or later manifest itself, whether you had locked the repository or not. However, if you had locked the repository, then it would be your coworker that would have to deal with the conflict. In the end, either you or him have to do it.