Erik
Erik

Reputation: 21

How do I manage conflicts between local git and github

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

Erik@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

Upvotes: 1

Views: 86

Answers (1)

bk2204
bk2204

Reputation: 76794

You should commit your changes before trying the merge. When Git is trying to perform a merge, it will write the result, including any conflicts, into your working tree. However, if you have uncommitted changes, doing so would destroy them, so Git will abort so as not to cause you to lose data.

If you commit your changes and your working tree is clean, then Git knows that you have a saved copy of the work, and if you don't like the result of the merge or if there are conflicts, you won't lose data.

It is also possible, as you've noticed, to stash your changes and reapply them later. That will also make your working tree clean, which will make Git happy. Which choice is right depends on what you're doing. If your change logically belongs on the branch you're on, and you're okay with keeping it right now, then commit it; if you'd rather work on it later or on another branch, then stash it.

Upvotes: 1

Related Questions