> For the complete documentation index, see [llms.txt](https://yu-sun.gitbook.io/essential-git-for-scientists/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yu-sun.gitbook.io/essential-git-for-scientists/cookbook/merge.md).

# Merge

### Notes

To merge two branches, you need to first checkout the branch to merge into. Then start merging:

```
git merge <branch-name>
```

If there's no conflict, then it will be a fast-forward merge. If there're conflicts, you need to resolve the conflicts.

### Resolving conflicts

Conflicts are marked by Git in the file, e.g.

```
<<<<<<< Updated upstream
this is a new file 5 in branch2
=======
This is file 5.
>>>>>>> Stashed changes
```

You can either

* manually edit the file to the final form; or
* tell Git which version to pick using the `--ours` or `--theirs` flag
  * `git checkout --ours <file>`
  * `--ours`: the version from the current branch (the one you checkout beforehand)
  * `--theirs`: the version from the other branch.

Once the conflicts are resolved, you can then commit the changes.
