0

I am having a doubt. Two developers clone a project from git repository. The two guys made changes in same file. Then they trying to add and commit. If they do like that, the guy who commits earlier can push with no conflicts while for the other one, merge conflicts will arise.

How to avoid this type of condition and also overcome it?

vaultah
  • 44,105
  • 12
  • 114
  • 143
nand
  • 117
  • 1
  • 9
  • This is one of the most basic git features and your post is wrong from the wrong used of commits instead of push. You need to at least understand a bit on git basics. http://progit.org/book/ch1-1.html – madth3 Mar 08 '12 at 06:09

3 Answers3

3

First, the second guy should git pull from the repository after the first has committed. Then he can do a git push himself. Potentially, there will be a merge conflict if they were both working on the same code. If that comes up, see here: How to resolve merge conflicts in Git?

Community
  • 1
  • 1
thedayturns
  • 9,723
  • 5
  • 33
  • 41
1

Also another option is to use rebase, instead of mergin.

http://book.git-scm.com/4_rebasing.html

This will keep a nice & clean tree :)

MartinElvar
  • 5,695
  • 6
  • 39
  • 56
0

It's always recommended to pull and push in short intervals to avoid merge conflicts.Merge conflicts only arise when changes have been done on same line in the file. Then those conflicts need to be resolved manually and remove the code which is not required and then commit the specific files where conflict occurred .

Bijendra
  • 9,467
  • 8
  • 39
  • 66