Skip to content

Resolving merge conflicts

Pier Luigi Buttigieg edited this page Aug 9, 2022 · 1 revision

🚧 under construction 🚧

Occasionally, git will let you know that a PR has merge conflicts with the master branch.

Resolving conflicts

Most conflicts will be trivial, such as unique class declarations and stanzas being in the same lines (keep both). Others will require one set of lines to be deleted in favour of another, or an artful merge (that usually requires a meeting with the submitter).

Search for git conflict tags in a reliable text editor. These are ======= as well as <<<<<<< and >>>>>>> followed by the commit identifiers that are in conflict.

Once you've resolved conflicts, git add, commit, and push and then set up the PR on GitHub to see if the merge is possible and if the QC checks are in good order.

If the QC passes and no merge conflicts exist, you can then use the GitHub merge function on their website or Desktop Client, or use the CLI to merge the branch with the PR into the master branch.

# Step 1: Clone the repository or update your local repository with the latest changes.

git pull origin master

# Step 2: Switch to the base branch of the pull request.

git checkout master

# Step 3: Merge the head branch into the base branch.

git merge BRANCH

# Step 4: Push the changes.

git push -u origin master

IF the PR is old or a number of other changes have been made to or merged into the master branch, you'll have to bring the PR up-to-date and check for conflicts.

git fetch
git checkout -b BRANCH origin/master
git fetch
git merge origin/master

PRs from branches

PRs from forks

If the conflicts on this branch are too complex to resolve in the web editor, you can check it out via command line to resolve the conflicts.

https://github.com/KrishnaTO/envo.git

Step 1: From your project repository, check out a new branch and test the changes.

# create a new branch from master in the repo, and name it
git checkout -b BRANCH master

# pull in the fork
git pull https://github.com/KrishnaTO/envo.git issue-443

You may get an error like this:

hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

Go with the git config pull.rebase false approach.

Step 2: Merge in the master branch to detect conflicts


# merge master into the branch you created in Step 1
git merge --no-ff master