Home > Blockchain >  git: how to force pull a branch if there are conflicts (becase someone force pushed)
git: how to force pull a branch if there are conflicts (becase someone force pushed)

Time:01-15

I need to checkout and pull our prod branch. I checked it out some time ago, and havent changed anything.

However people have force-pushed changes to prod branch, causing thousands of conflicts with my local copy when I try to pull.

If I try to delete the prod branch, I get:

% git branch -d prod
error: Cannot delete branch 'prod'

If I try to switch away from the prod branch, I can't:

% git checkout main
ui.front/src/components/Navigation/Navigation.tsx: needs merge
error: you need to resolve your current index first

Any suggestions?

Is there some sort of force checkout or force pull? checkout -f doesnt help.

May be something like this would work, but I'm too scared to it unless someone can confirm it won't break anything and its the right thing to do:

git fetch --all
git reset --hard origin/prod

CodePudding user response:

  1. Cleanup your current prod branch by either stashing, recommended (git stash) or if you don't care about the changes (git reset --hard)
  2. git branch -m prod_backup # to rename your current prod banch to prod_backup (just in case)
  3. git fetch
  4. git checkout prod you should now have the changes which your colleagues pushed

CodePudding user response:

I could not find a way to delete the offending branch, but I can confirm that the following worked:

git reset --hard origin/prod
git pull
  •  Tags:  
  • Related