Git force dev into master from PR

When conflicts are crazy and I just want to have dev in master and PR is required.

1. Make sure you’re in the repository root

cd /path/to/repository/root

2. Get the last commit in dev

git checkout dev
got log -n 1
> b2ed68964660648860bcf41d096e71b5d49226ae

3. Create branch from master

git checkout master
git checkout -b sync-with-dev 

4. Remove EVERYTHING first from sync-with-dev branch

git rm -rf .

5. Restore everything from the target commit

git checkout b2ed68964660648860bcf41d096e71b5d49226ae -- .

6. Also restore any files that might have been gitignored

git checkout b2ed68964660648860bcf41d096e71b5d49226ae -- ':!.git'

7. Add all changes (including deletions)

git add -A

8. Commit

git commit -m "Sync master with dev"

9. Push

git push origin sync-with-dev

Now just PR into master and merge without conflicts.

Verify

git checkout dev
git pull origin master --no-commit --no-ff

No pending changes should be available, since now master is identical to dev