Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not see remote changes after 'git pull --rebase'

Tags:

git

I am trying to do a 'git pull --rebase', but I don't see any remote changes. When I do a 'git status' I see ' Your branch is ahead of 'origin/master' by 12 commits.'

But I am current on my 'dev' branch, not master.

$ git branch
  master
* dev

And my 'dev' branch should track 'remotes/origin/dev'.

All I want is I am working on 'dev' and I want to get remote changes on remote dev.

But I did 'git pull --rebase' which some how pull remote 'master' changes to my 'dev' branch.

Can you pleases tell me how can I recover from my situation?

  1. remove the changes I pull in from remote 'master' branch mistakenly (after i did 'git pull --rebase')

  2. pull in the changes on remote 'dev' branch on to my 'dev' branch.

Thank you.

like image 927
michael Avatar asked Oct 12 '22 12:10

michael


1 Answers

It sounds as if your dev branch was originally based on origin/master instead of origin/dev, or somehow dev has been changed to track origin/master anyway. You can check this with:

git config branch.dev.merge

If that says refs/heads/master instead of refs/heads/dev you can change the upstream branch for your dev branch with:

git checkout dev
git branch --set-upstream dev origin/dev

Then, to fix your branch, I would:

  1. Make sure that you're on the dev branch with git checkout dev
  2. Make sure that git status is clean
  3. Create a branch to save where you were (for safety): git branch dev-wrongly-rebased
  4. Use git reflog to find the commit before you rebased onto origin/master
  5. Reset dev to that point git reset --hard COMMIT-BEFORE-BAD-REBASE
  6. Finally, do git rebase origin/dev

My preference when rebasing is always to do it in two steps, e.g.:

git fetch origin
git rebase origin/dev

... since I think that's less error-prone than git pull --rebase. I hope that's of some use.

like image 122
Mark Longair Avatar answered Oct 18 '22 03:10

Mark Longair