Home > Software design >  git checkout of a branch is giving "Your branch and 'origin/prod-env' have diverged&q
git checkout of a branch is giving "Your branch and 'origin/prod-env' have diverged&q

Time:11-20

we have a dev branch (main), and a production branch (prod-env). I have main checked out, up to date, and no changes (clean). I want to see what is on prod, so tried to checkout the prod branch using:

$ git checkout main

$ git pull

$ git status

On branch main Your branch is up to date with 'origin/main'.

$ git checkout prod-env.

This gives:

Your branch and 'origin/prod-env' have diverged,  and have 26 and 333 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

This odd as i have never checkedout out prod-env, and I have no changes. I have never used rebase or force due to danger.

How do I

  1. backout of where I am now, and

  2. checkout the prod-env branch without getting these (apparently) non-existent errors?

Im guessing another solution might be to clone the repo in a different location, and only checkout prod-env (never checkout main). Will that avoid this problem?

I certainly don't want to merge anything with prod-env, as that wont tell me whats on prod-env.

CodePudding user response:

I would do a hard reset on your local branch, as long as you are sure that you haven't made any updates locally that need to be on your remote version of the branch.

git reset --hard origin/prod-env

This will reset your local version of prod-env to match the remote version.

CodePudding user response:

This odd as i have never checkedout out prod-env

You did though, and someone squashed or rebased some commits that you still had locally.

Just do a git reset --hard origin/prod-env to reset it to the origin's state.

  •  Tags:  
  • git
  • Related