< YALU STUDIO >

Resolving merge conflict while using git pull

Word count: 169 / Reading time: 1 min
2018/08/05 Share

After using git pull command, sometimes message below would pop up:

1
2
error: Your local changes to '<filename>' would be overwritten by merge.  Aborting.
Please, commit your changes or stash them before you can merge.

It means that the update is conflict with the local content, you should save your work before you merge them.

Save your local modification

Go to the working directory, and

1
$ git stash

You can use git stash list to see what you have saved.

Pull

After that, you can pull.

1
$ git pull

Recover the saving

1
$ git stash pop stash@{0}

It would inform you that:

1
2
Auto-merging <filename>
CONFLICT (content): Merge conflict in <filename>

The system automatically merge them, but you have to deal with the conflict manually.

Resolve the conflict

Open the conflicted file, you can see something like:

1
2
3
4
5
<<<<<<< Updated upstream
int i, j; # what we pulled
=======
int i, z; # what we stashed
>>>>>>> Stashed changes

Decide which one you want to keep.

CATALOG
  1. 1. Save your local modification
  2. 2. Pull
  3. 3. Recover the saving
  4. 4. Resolve the conflict