In my workplace, we use a rebase workflow. I recently helped three of my colleagues with the following problem, so I figured it was worth posting a Q&A to help more people and provide a reference to point my coworkers at.

Suppose I run the following series of commands to create a git repository and initialize it with some data and a single commit.

```
git init .
cat > MyFile.txt <<'EOF'
> Line 1
> Line 2
> Line 3
> Line 4
> EOF
git commit -m 'Initial commit'

```

Then, I make a branch and add a commit to modify a particular line.

```
$ git checkout -b MyFeature
Switched to a new branch 'MyFeature'
$ ed MyFile.txt
28
2s/$/ This is the initial implementation of my glorious feature
Line 2 This is the initial implementation of my glorious feature
wq
86
git add -u
git commit -m 'WIP Add glorious feature'

```

After sending it off for review, I then work on a different feature that depends on this feature, and make a new commit.

```
git checkout -b MySecondFeature
cat >> ThisFileDependsOnMyFile.txt <<'EOF'
> This commit touches a completely different file.
> EOF
git add ThisFileDependsOnMyFile.txt
git commit -m 'Add Feature2'

```

Now my reviews for the first feature come back, so I make some changes to it and then merge it into master.

```
git checkout MyFeature
sed -i '2s/initial/final/' MyFile.txt
git add -u
git commit --amend -m 'Add glorious feature'
git checkout master
git merge MyFeature

```

Finally, I attempt to rebase MySecondFeature onto master. Unfortunately, it blows up, even though the new commit on MySecondFeature does not even touch the file that conflicts.

```
git checkout MySecondFeature
git rebase master
First, rewinding head to replay your work on top of it...
Applying: WIP Add glorious feature
Using index info to reconstruct a base tree...
M       MyFile.txt
Falling back to patching base and 3-way merge...
Auto-merging MyFile.txt
CONFLICT (content): Merge conflict in MyFile.txt
error: Failed to merge in the changes.
Patch failed at 0001 WIP Add glorious feature
hint: Use 'git am --show-current-patch' to see the failed patch
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".

```

**How does one avoid these spurious merge conflicts when branching off a branch that subsequently has its history rewritten?** Note that we can always manually fix the conflict, but it's a pretty huge waste of time to keep doing this.

To make this easier to discuss, here are a couple of hashes:

```
git log MySecondFeature
hq6:GitPlay hqin$ git log
commit 061fc8448e93f0e31239b2f4806d5caac6bfe578 (HEAD -> MySecondFeature)
Author: ***
Date:   Sun Dec 15 15:36:21 2019 -0800

    Add Feature2

commit f878084412c04542e297cb5c52b0fb6f6a2b2870
Author: ***
Date:   Sun Dec 15 15:30:45 2019 -0800

    WIP Add glorious feature

commit fe88218ac2432e086a40f052bfa4e7c759f677b4
Author: ***
Date:   Sun Dec 15 15:26:18 2019 -0800

    Initial commit

git log master
commit 522cc625b709b37c4ccfd1878465f8da30f9e082 (master, MyFeature)
Author: ***
Date:   Sun Dec 15 15:30:45 2019 -0800

    Add glorious feature

commit fe88218ac2432e086a40f052bfa4e7c759f677b4
Author: ***
Date:   Sun Dec 15 15:26:18 2019 -0800

    Initial commit

```