Essential Git for Scientists
  • Introduction
  • Basic Concepts
    • Version Control
    • Git
    • Repo
    • Commits
    • Branches
    • Remotes
    • GitHub
    • De-centralisation
    • Summary
  • Basic Operations
    • Install Git
    • Create a Repo
    • Make a Commit
    • Inspect a Previous Commit
    • Revert a Change
    • Make a Branch
    • Extend a Branch
    • Fast-forward merge
    • Resolve conflicts
  • Intermediate Concepts
    • Commits
    • Three Trees
    • Rebase
    • Fetch
    • Pull
    • Push
  • Advanced Concepts
    • Reset
    • Interactive rebase
    • Formatted patches
    • Blame
    • Stash
    • Log filter
  • Cookbook
    • Undo
    • Branches
    • Diff
    • Stash
    • Merge
    • Hooks
    • Squashing
    • Rebase
    • Interactive Rebase
    • LFS
    • Submodules
    • Remote
    • Force push
    • Identify merged branches
    • Formated patches
    • Apply patches
    • Interactive rebase
    • Squash commits
    • Pull rebase
    • Log
    • Blame
    • Biset
    • Reset
  • Exercise
    • Exercise 1
    • Exercise 2
Powered by GitBook
On this page
  • Notes
  • Resolving conflicts
  1. Cookbook

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.

PreviousStashNextHooks

Last updated 1 year ago