Home > Back-end >  What's the proper way to handle incorporating changes from another's commit or pull reques
What's the proper way to handle incorporating changes from another's commit or pull reques

Time:12-24

Sorry if the title isn't too clear, I'm not exactly sure how to word this myself, but I'll try to explain in more detail here.

Back in October I started working on a new project - a music bot for Discord written in Python, because I didn't like the existing self-hosting options I could find at the time. I decided to make a repository for it on GitHub, both for others to use and so I could use git pull to update the files more easily on the VPS I'm using to host my instance of it.

No one has made any forks or pull requests of it yet, but lately I'd got to thinking about it and realized I'm not entirely sure what the process for integrating someone else's code into mine would be?

As in, if someone starts working on a bug fix or a feature of their own, makes a PR, and I want to accept it and merge with mine - but I'm also separately in the middle of doing some work in my local files, is there any sort of proper procedure there for combining their changes with mine besides just manually looking over it and deciding how to integrate it?

CodePudding user response:

Although git does allow you to set remote repos to feature branches, you generally will only ever pull / PR into integration branches of some kind.

A common pattern would be to have a master and a develop branch. the Master branch is a source of truth, and PR's are merged from develop to master.

develop is an integration branch. It is branched from master, and changes are PR'd into develop, then eventually PR'd into master.

Developers should cut branches from develop, make changes, then PR into develop for review.

When you and a colleague are working on changes in the same project, it is important to PR and integrate often so others can integrate the work into their own branches.

It is common practice to constantly be performing git pulls on develop or taking in the latest changes that developers may have made.

So to answer your question, you both integrate into a common branch and pull those changes into your own feature branches as you go. Make changes often so it's easier to merge.

See gitflow for a commonly adopted branching strategy.

CodePudding user response:

The problem also applies to simpler cases, e.g. when you make changes on two different computers.

is there any sort of proper procedure there for combining their changes with mine besides just manually looking over it and deciding how to integrate it?

  1. In majority of merges there are no conflicts do deal with because changes are in different files and even if the changes affect the same files git may be able to resolve them automatically.
  2. Rebasing can help lower the number of conflicts that git cannot resolve automatically.
  3. merge-strategies can help too
  4. In a case where there genuinely is a conflict and it's not oblivious what to do, then you will need to resolve them yourself. Many tool provide a 3-way merge to simplify this process.
  • Related