1

We are two developers that we started working with Github. We are beginning to understand how it works, but we cannot find a way to work on the same class without problems. There is a way to do it or we have to give up? Thanks in advance for the answer.

Pietro Teggi
  • 104
  • 7
  • 1
    Normally you commit, then pull (the commit of the other developer that pushed), then you resolve the conflicts (if any), and then you push your commit and the merge commit. – Willem Van Onsem Dec 04 '19 at 10:07
  • You can create 1 class each, then when you are done commit and merge the classes – PEPEGA Dec 04 '19 at 10:07
  • would not advise. working on the same files is going to cause merge conflicts. – Glenn van Acker Dec 04 '19 at 10:07
  • 4
    I suggest you start from some documentation/tutorials: https://guides.github.com/activities/hello-world/ – trailmax Dec 04 '19 at 10:07
  • 2
    If you want to work on the same class, and to make sure you won't get merge conflict because both of you are working on the same file, you can make your class [`partial`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods). Doing this, you can split the class definition in 2 or more files and avoid conflicts – Cid Dec 04 '19 at 10:14

2 Answers2

1

What problems are you people facing ? Its quite simple.

You both can work on the same class, when one of you is done with the work, he will push the code to the GitHub, then before the second person pushes the code, he has to pull the code from the GitHub (remember it is the best practice to pull the code from repository before pushing). When you pull the code, you will get conflicts. Resolve those conflicts (Its very easy to resolve the conflicts using VS). After conflicts has been resolved, code can be pushed to GitHub. And this cycles will continue.

So, what is the problem in that ? or what problem you guys are facing ?

Waleed Naveed
  • 2,293
  • 2
  • 29
  • 57
  • 2
    "remember it is the best practice to pull the code from repository before pushing" unless you force the push, it won't work anyways – Biesi Dec 04 '19 at 10:40
  • The problem that we faced is while merging. Visual studio delete the codeof the person that is merging – Pietro Teggi Dec 04 '19 at 10:43
  • No, i have never seen that. I think you are not merging it correctly. I think while merging you select the file of the other developer, that's why you lost your changes. You have to merge the changes manually. @PietroTeggi. "SourceTree" is a tool which can also help you in this regard. But you can do the manual merging in VS too. If you still have the problem, its better that you show some example or screen shot of how you are merging and all that. – Waleed Naveed Dec 04 '19 at 11:37
0

You can merge conflicting codes if you are working on two different methods in the same class.so the best method is to specify who works on which method before hand. you can refer to this link to learn about resolving the conflicts.

Nima Habibollahi
  • 360
  • 5
  • 16