Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

First-time question. I'm doing a tutorial on git and covering the instance where the code on the server has been updated and the local code has been independently updated so there is a conflict.

In the video, the lecturer does a git pull and this tries to get the files. The dialog gets details then says

Auto-merging hello.html

but mine, at that stage, says

error: Your local changes to the following files would be overwritten by merge:

        hello.html

I ended up not being able to push or pull changes until I resolved the conflict. I ended up having to do

git stash

git pull

git stash apply --index

Is there a configuration I need to apply to my local git to get it to try the auto-merge?

for clarity I get

$ git pull

error: Your local changes to the following files would be overwritten by merge:

        hello.html

Please commit your changes or stash them before you merge.

Aborting

Updating 7ed9dbb..0525225

Timothy@DESKTOP-TI7OP0E MINGW64 /e/gitrepo/webcourse (master)

$ git commit -m "save"

On branch master

Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.

  (use "git pull" to update your local branch)

Changes not staged for commit:

        modified:   hello.html

no changes added to commit

1 Answer

0 votes
by (12.4k points)

Before merging make sure that you have made commit to your changes. When you try to perform the merge, Git will write the result including conflicts into the working tree. And if you have uncommitted changes performing merge will destroy them, so Git aborts as not to cause you any data loss.

Now if you have committed your changes and the working tree is clean, then Git knows that you have saved your work and if you don't like the result of merge or conflicts you don't lose your data.

Here it is also possible to stash your changes, which will make your working tree clean. Now if the changes are logically on the branch you are on and you want to keep it then commit it or in case you want to work on it later or on any other branch then you can stash it. The choice is completely yours.

For more information on Git, you can join git training.

You can also check out:

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...