0

I have a file called index.html in master branch. I create dev branch and switch into the dev branch

git branch dev
git checkout dev

I then edit index.html and commit the change

git commit -m "first change" index.html

I am still in the dev branch. Now I want master to have this new feature so I try to merge the dev branch into master

git merge master

but I get

Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

It seems I am stuck, I have to do git merge --abort but how can I ever do the merge?

argabri
  • 1
  • 1
  • 1
  • Possible duplicate of [How to resolve merge conflicts in Git](https://stackoverflow.com/questions/161813/how-to-resolve-merge-conflicts-in-git) – Krishna Mar 12 '19 at 18:33
  • 1
    technically, this shouldn't raise any merge conflicts.. did you change the index.html in **master** after you created the branch from master? – Mr. Alien Mar 12 '19 at 18:34
  • You will face merge conflicts when the same file has been edited in the master branch. Read this https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts to learn how to resolve it – Krishna Mar 12 '19 at 18:36

2 Answers2

0

You are not stuck, git tells you "Automatic merge failed; fix conflicts and then commit the result."

so fix the conflicts and then commit the result...

if you googled it you would have find this : https://stackoverflow.com/a/163659/1346690

Heetola
  • 5,791
  • 7
  • 30
  • 45
  • Does this mean every time I wish to merge my dev branch into master I need to use the mergetool? If that is the case aren't I do something wrong with merging? This happens every time I do what I did above. – argabri Mar 12 '19 at 18:34
  • no that is weird. Conflicts can arises when you have a modification on the same file on both branches. Here you had no change on index.html in the master branch so it's definitly weird. – Heetola Mar 13 '19 at 06:17
  • what did merge tool showed you? what were the conflicts about? – Heetola Mar 13 '19 at 06:17
0
git branch dev
git checkout dev

Just use one command git checkout -b dev.

Now I want master to have this new feature so I try to merge the dev branch into master

git merge master

To merge dev into master the proper commands are

git checkout master
git merge dev

In case of conflicts resolve them using editor, add resolved files with git add and commit.

Community
  • 1
  • 1
phd
  • 82,685
  • 13
  • 120
  • 165