Home > Software engineering >  How to deal with working on same git files?
How to deal with working on same git files?

Time:08-13

I'm pretty new to git.

My colleague worked on same files as me, even though he knew I was also working on that files, and he pushed changes.

Can I pull his changes to my local branch without losing my changes?

Is there any way of dealing with this mess? Also, I refactored some files names.

CodePudding user response:

Working on the same files are a usual practice.

If you pull something which another user yet changed and pushed, may generate conflicts.

In such case you have to deal with the **conflict resolution" scenario, but you don't loose any of you changes.

At Atlassian you can get a good guide.

CodePudding user response:

Git is actually extremely good at handling these conflicts.

If you worked on two different areas of the same file, Git should be able to merge the two changes with no problem.
If your work actually conflicts, you'll get a merge conflict, with yours and you colleague's changes, and have to manually resolve which one (or a mix of the two) to take. GitLab has a neat guide on this subject for some details.

Note that "conflicts" in this context means only actual conflicts in the files edits, not logical conflicts. E.g., if you added a piece of code that calls some_function() and your colleague removed some_function's definition, there would be no textual conflict, but your code just won't work after merging. Therefore, it's important to test your code after all the conflicts have been resolved.

  •  Tags:  
  • git
  • Related