Search code examples
gitgit-rebasegit-pullgitpythongit-merge-conflict

How to create a git pull --rebase conflict for testcase?


I would like to create a test case that solves a rebase conflict, but first I need a way to cause the rebase conflict when doing a git pull --rebase.

Is there a programmatic way of creating a rebase conflict scenario?

The test will be for a GitPython program.


Solution

  • To quickly create a rebase conflict, you can do the following:

    1. modify a file, commit and push to the remote repository
    2. make a change to the same file on the same line
    3. amend the last commit with git commit -a --amend -C HEAD. The HEAD commit hash has now changed
    4. run git pull --rebase

    You'll end up with a conflict at the line you modified.

    To clean up: you may want to git reset --hard origin/[your-branch] after your test to get back to step 1.