0

I have a master feature branch in which all the feature development are merged during the development cycle. In case of any changes to the file, I want to pull the file from the master feature branch to avoid merge conflict. I tried the below approach but facing issue.

git checkout <Branchname>
git fetch
git checkout <masterfeature branchname> -- file1
<modify the code<file1> in local repo>
git add file1
git commit -m "<msg>"
git push

The changes are successfully reflected in Remote Feature branch but I am getting a merge Conflict when trying to merege to Master Feature branch. Please suggest how to proceed. The file was not even present in the feature branch and I pulled it from the Master feature branch and modified. Still it is giving me Merge Conflict issue.

Please Help! Thanks in Advance

Rahul Raj
  • 71
  • 6
  • 2
    What does `--file1` mean? Don't you want a space in there? – CryptoFool Feb 28 '21 at 19:20
  • 1
    Why do you run `git checkout --ours file1` after modifying the `file1`? that step seems unnecessary, and it probably the crux of the issue (?) – ErikMD Feb 28 '21 at 19:50
  • The commands and branch names here are too fake and inconsistent to make sense of. There is no merge mentioned so how can there be a merge conflict? – matt Mar 10 '21 at 19:25
  • I think the problem is that you are now effectively adding this file independently in two branches, with different contents in each case, and Git doesn't like that. There is indeed a conflict: master-feature branch has empty -> file1-version1 and Branchname has empty -> file1-version2. – joanis Mar 10 '21 at 19:31
  • If you're going to merge master-feature into Branchname anyway, I would suggest doing that merge first, and then doing the changes you want to make to file1 on Branchname. – joanis Mar 10 '21 at 19:32
  • If you must add file1 on its own first, then you might try to do a commit where it has identical contents to that in masterfeature, and commit the changes to file1 you need as a separate commit. Then, when you merge, Git might (or might not, no guarantees here!) be able to figure things out. – joanis Mar 10 '21 at 19:34
  • Nevermind, I just tested, and doing it in two commits does not help Git merge figure it out. Although it does make the commit history easier to understand by a human. You'll just have to resolve the conflict by hand when you do the merge. – joanis Mar 10 '21 at 19:39
  • 1
    Voting to reopen: this question is about resolving the conflict that comes up when merging two branches that each independently added the same file, which is not addressed by the linked duplicate. – joanis Mar 10 '21 at 19:40

0 Answers0