-3

me and a friend are working on a project, and we are both doing seperate things (he does UI, I do some data structure), and his code relies on my code. Right now we have a master, a develop and 2 feature branches (one for UI and one for data structure). How can he test his UI with my commits, without making one huge mess out of the commit history and without committing to develop (since both features are not done yet)?

Sorry if it's a beginner question, quite new to git!

3
  • Sharing your research helps everyone. Tell us what you've tried and why it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask Commented Jul 7, 2020 at 13:32
  • Can you clarify how is it that he needs your work but somehow is working without it? Does he need it or not? It can't be both. Commented Jul 7, 2020 at 13:34
  • 3
    To me it feels like you are both working on different aspects of the same feature. That would imply to should be working both on the same feature branch. Commented Jul 7, 2020 at 13:39

2 Answers 2

1

There is no good way to test code when such a dependency exists. This leaves two solutions:

  • resolve the dependency. Merge the data structure stuff first before working on the UI.
  • break the dependency. Introduce some interface that decouples UI and data so that they can be worked on truly independently. For testing, you could introduce mock implementations for those interfaces.

There's another alternative that works quite well when you're only two persons: just work on everything together in a pair-programming session. That might sound slow and inefficient, but can be very effective since everyone understands all the code, and problems are spotted earlier. In my experience, doing pair programming from the start ends up being much faster than trying to resolve a giant merge of different feature branches.

3
  • So front-end and back-end should be done on the same branch? I was thinking I could rebase his commits onto my branch everytime we want to test something, and when everything works, we merge my feature branch with develop. EDIT: Wait then we might aswell just work on the same branch right? Commented Jul 7, 2020 at 15:02
  • @JorenvandenBerg Very broadly, my point is that you should work together, not against each other. Details: With Git, everyone has their own (local) branch. If you share a remote branch you will have to merge upon each push/pull. Using a common remote branch (“continuous integration” in its original meaning) can work but requires discipline to only push good commits – don't “break the build”. Commented Jul 7, 2020 at 18:54
  • Rebasing sounds nice and simple but that's not always the case: when you rebase some commits, you create an alternate history that replays those commits on top of another branch. If someone else rebases a remote branch you've been working on, reconciling the Git history is nontrivial. Most Git users can't do it. So only rebase stuff if no one else is working on it, or if everyone has finished working on it. Commented Jul 7, 2020 at 18:54
0

If I were him I would rebase his branch onto yours (and pull in rebase mode every time you push some new code).

Once the changes are ready to be merged, you merge your branch first, then his branch and everything should be fine.

Be careful though, rebase is quite an advance git command and it can cause some serious problem...

1
  • So if I understand correctly, I choose my branch, then rebase his branch, whenever he has pushed new commits to his branch. Then those commits were technically applied to my branch right after it was created, before I started working on it, and his commits would be "deleted" from his branch? Commented Jul 7, 2020 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.