It’s inevitable that once you starting using Git you’ll run into merge conflicts; especially, when working with a team of developers. Use this step-by-step Git conflict solving workflow if you’re confused by how to actually solve Git conflicts using the command line. There are tons of GUI tools to accomplish this, but it’s always great to know the underlying process and commands.

Show the commit log

git log --color --oneline

Look for the commit hash preceding your latest commit (e.g.7783c59)

48c89dc latest commit message
7783c59 this is the commit you want

Reset to that commit

git reset 7783c59

Stash your changes

git stash -u

Merge in the branch that previously caused the conflict (replace conflicting-branch with the actual branch name)

git merge conflicting-branch

Apply the stash to the branch

git stash apply

Deal with any conflicted files and add them to the changes

git add /path/to/conflicted/file

Create a new commit with all changes after the conflicts are resolved

git commit -a -m "commit message"

Force an update to the remote repository (replace branch-name with actual branch name)

git push origin +branch-name

If you feel at any point that you’ve messed up, just start over by doing a hard reset and then apply the stash again

git reset --hard 7783c59
git stash apply

At this point you can remove the stash. If you’d like to be more explicit, use the stash’s hash when dropping the stash.

git stash drop