Skip to content

How to fix Merge Conflicts

Conflicts can arise because many contributors work on the repository, and changes can break your PR which is pending a review and merge.

Since we squash all commits, you may not need to do a rebase. However, if a rebase is requested, check our For Usual Bug Fixes and Features or For Upcoming Curriculum and Features guides to learn how to do this process for your corresponding PR.

When you are working on regular bugs and features on our development branch main, you are able to do a simple rebase:

  1. Rebase your local copy:

    Terminal window
    git checkout <pr-branch>
    git pull --rebase upstream main
  2. Resolve any conflicts and add / edit commits

    Terminal window
    # Either
    git add .
    git commit -m "chore: resolve conflicts"
    # Or
    git add .
    git commit --amend --no-edit
  3. Push back your changes to the PR

    Terminal window
    git push --force origin <pr-branch>

When you are working on features for our upcoming curriculum next-* branches, you have to do a cherry-pick:

  1. Make sure your upstream comes in sync with your local:

    Terminal window
    git checkout main
    git fetch --all --prune
    git checkout next-python-projects
    git reset --hard upstream/next-python-projects
  2. Take a backup

    a. Either delete your local branch after taking a backup (if you still have it locally):

    Terminal window
    git checkout <pr-branch-name>
    # example:
    # git checkout feat/add-numpy-video-question
    git checkout -b <backup-branch-name>
    # example:
    # git checkout -b backup-feat/add-numpy-video-question
    git branch -D <pr-branch-name>

    b. Or just a backup of your PR branch (if you do not have it locally):

    Terminal window
    git checkout -b <backup-branch-name> origin/<pr-branch-name>
    # example:
    # git checkout -b backup-feat/add-numpy-video-question origin/feat/add-numpy-video-question
  3. Start off with a clean slate:

    Terminal window
    git checkout -b <pr-branch-name> next-python-projects
    git cherry-pick <commit-hash>
  4. Resolve any conflicts, cleanup, and install dependencies and run tests

    Terminal window
    pnpm run clean
    pnpm install
    FCC_SUPERBLOCK='<superblock-name>' pnpm run test:curriculum:content
    # example:
    # FCC_SUPERBLOCK='python-for-everybody' pnpm run test:curriculum:content
  5. If everything looks good, push back to the PR

    Terminal window
    git push --force origin <pr-branch-name>