0

I'm working on a project which has different branches with different developers. Each project has submodules and .gitmodules differs in every branches, so this cause a merge conflict when the main branch holder try to merge. I tryed different way to resolve it but with no results, imagine that I have no access on the main branch.

Anyone that encounter my same problem? How did you resolve it? Thank you in advance.

5
  • just as an idea, as it appears to be almost like a environment/developer specific file why not add it to gitignore. maintaining the master file manually might be easier than resolving conflicts Commented Mar 25, 2022 at 10:41
  • First of all, thank you. The problem is that I need to keep that file, for example, two .gitmodules of two branches need to be unique when are merged in the Master. What I was thinking is to use a third branch to store .gitmodule only and other developers should copy that file and update it. Maybe there is a clever way to do it (for sure). Commented Mar 25, 2022 at 13:23
  • I guess my first question would be, what is the state you want in master after merging? Do you want master to get the .gitmodules from the branch you're merging from, or keep its own? Frankly, this config seems quite fragile. Why does each branch have different submodules exactly? Are the different developers integrating with different submodules, or are they just on different servers? And why does it make sense for them to be working in the same repo, if what they're working on is so different? Commented Mar 25, 2022 at 13:50
  • In any case, when you want to merge onto master, you should create a branch that has the end state you want on master, and merge/PR that into master. So you resolve any conflicts in that branch before merging it to master. Commented Mar 25, 2022 at 13:51
  • Note that files (like .gitmodules) in Git are not in branches, but rather in commits. Branch names move; commits never change once made. We use branch names to find commits, and move branch names around so that we find different commits. The file contents within any one given commit are constant. Commented Mar 26, 2022 at 1:35

1 Answer 1

1

Whenever you want to merge something into master, the best approach is to create a branch where you create the end state you want on master, and merge/PR that branch.

So when a developer wants to merge something from their project branch to master, they would create a new branch, merge master into it (if necessary), fix any and all conflicts and bring it to the state that makes sense with respect to master, which includes fixing the .gitmodules configuration in your case. They would then submit a PR to merge that branch into master. There should be no conflict now, since the conflicts were resolved before doing the PR.

This advice holds for any and all PRs: it's good practice to make the person submitting a PR resolve the conflicts on the PR branch, rather than have the owner of the master branch do it. And even when the owner resolves the conflicts for the submitter, they can do it on the PR branch before accepting the PR. (I might do that for one-time contributors if I don't think it's worth teaching them how to resolve their conflicts, but I consider it a good learning opportunity so I generally prefer to spend the time showing the contributor how to do it instead.)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.