0

So I started using github today. Basically, there are two of us (programmers) who will work on a single project with a PIC microcontroller. I have experimented a bit and read a couple of stuff and terms such as branches, commit, master, etc.. So let's say I just have one main.c file containing 4 lines.

This one is our master file. There are two of us developing at the same time. Now we make two branches out of this master (so basically a snapshot of this current code). The two branches are "branch1" and "branch2", with me making changes using branch1 and my partner using branch2. I inserted a line "dummy = 0" between line2 and line3 while my partner insert "dummy = 0" between line3 and line4. So at the end of the day, I will commit my changes to branch1, pull a request to merge my changes to master. Now, how does my partner do to make his changes to the new master file (after I committed mine)? Note that we started off from the same master file. Thanks

What we did so far: We haven't tried making edits at the same time yet. What we did for now was that I asked him to make edits on branch2, then try to pull a request so that I can approve it so that his edits from branch 2 carries out to the master. My problem lies in the fact that we would most likely start from the same master code each day and so every change being made each hour would not carry on to the other one's copy

  • Hello, and welcome to SO. Try not to put relevant information in the comments. [edit](https://stackoverflow.com/questions/61520783/github-multiple-branches-developers#) your post, instead! Happy hunting – Daemon Painter Apr 30 '20 at 10:06

1 Answers1

0

Git is a versioning system working on incremental differences.

In your scenario, you have 3 branches: master, branch1, branch2. You are both working on the same file in the two dev branches (not master).

Once you pushed your edits with a commit on branch1, your partner won't see anything in branch2: they are divergent paths.

What your partner has to do, is to merge your latest commit into branch2. In this way, the two divergent paths have met, and became one again. If you'll continue on branch1, rinse and repeat the process.

Since you stated that you both added lines in the same file, expect conflicts: "merging" means start from the file as it was back then (at the beginning of branch2), then replay all edits that were done in each commit, in that order. When you'll have to put together the edits of both branches, probably this will conflict. Say for instance that you added dummy = 0 on line 4. Your partner did it as well, but wrote dummy = 1 on line 4. Git doesn't decide for you, you'll have to resolve the conflict and decide which one to keep.

Note that I haven't mentioned master. I'll refer you to gitflow for that, is a little bit too broad of an argument for a single question.

Daemon Painter
  • 2,517
  • 2
  • 19
  • 33
  • "What your partner has to do, is to merge your latest commit into branch2. In this way, the two divergent paths have met, and became one again. If you'll continue on branch1, rinse and repeat the process." I assume this is always safe if we collaborate such that we don't cross paths on development? Like for ex. if we have 4 different c files (c1-c4), I only work on c1 and c2 while he/she works on c3 and c4 only? – user139731 Apr 30 '20 at 10:20
  • yes: what happens on `branch1` doesn't happen on `branch2` until a `merge`. The merge may generate conflicts. – Daemon Painter Apr 30 '20 at 11:43