Merging branch into master after master added .gitignore?

Hello community, I have a question regarding a messy situation I’m not sure about. One of my colleagues, person A, set up a repo without a .gitignore, so we eventually added one and cleared out the cache and everything’s peachy. Except I forgot that another colleague, person B, made a branch for himself before this happened. Could B successfully merge his work, or would he have to delete that branch and copy his work over to a new one?

Depending on what B changed, B could successfuly merge their work, yes. The best thing to do when concerned about merge conflicts is for B to pull the latest master and merge those changes into their own branch to resolve them locally. Here’s how that could be done, assuming they’re on their branch already:

git fetch
git merge master

Then resolve any merge conflicts before merging back into master.

If you’re concerned that person B may have inadvertently committed files on their own branch that would now be ignored by the new .gitignore file, they could try rebasing their branch on the new master with the following:

git fetch
git rebase master

This would essentially “re-play” the changes they made on top of the latest master. This might allow the .gitignore changes to prevent the committing of the files intended to be ignored. I haven’t tested it but it is worth a try.

To be safe, create a new branch to do the rebase from. That way you can always back out by changing back to the pre-rebase branch and delete the new branch. If it works, you can delete the pre-rebase version.

I hope that helps! Let us know if you have more questions.