When a merge conflict happens there is an unplanned change of code to resolve the issue. Can I check if another person is working on the same section of code as I am and co-operate before the conflict occurs?
2 Answers
Git only finds out that someone else has changed the repository when you either ask it if there's been a change, or if you try to change it. So in short: no. Communication with your team outside of git is possible, though. Advisable, even.

- 7,499
- 2
- 23
- 38
Git is a DVCS (where the D means decentralized). There is no knowledge of other collaborators' local copy of the repository.
I assume that you are using a central remote (git server) and that what you mean is that the implicit merge done when you pull from your remote after another collaborator pushed their changes, results in a merge conflict on your end.
In the following test, remote is your central repository (it could be a URL, here it's just a local directory, but git doesn't care), foo is your local copy and bar is your colleague's.
mkdir gitTests
cd gitTests
#Create our remote (server)
git init --bare remote
#Create a new repo in directory foo
git init foo
cd foo
echo 'a' > a
git add a
git commit -m 'First commit'
#Set the remote as our central repo and push to it
git push --set-upstream ../remote master
#Create our colleague's repo from the remote
git clone ../remote ../bar
#Colleague makes a commit, pushes to remote
cd ../bar
echo 'b' >> a
git commit a -m 'Colleague commit'
git push
#We work on the same file, creating a merge conflict
cd ../foo
echo 'c' >> a
git commit a -m 'Our conflicting commit'
git push
#We get an error, because our push is non fast-forward, we need to pull before
git pull
#Here, we get a local merge conflict
As you may have understood, there is only a conflict for you trying to push. At that moment, only your colleague's commit is on the remote and you can call them to your desk to resolve the conflict together. Once that is done, you can push, they pull, and the problem is solved.

- 443
- 3
- 9
-
Thank you for the answer, it will take a little while for me to work through it – rustystylus Oct 12 '14 at 03:48