Do not see remote changes after 'git pull --rebase'

I am trying to execute 'git pull --rebase', but I do not see any remote changes. When I do git status, I see that your branch is ahead of "origin / master" by 12 commits. ''

But I am in my "dev" branch, not master.

$ git branch master * dev 

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

All I want is work on "dev", and I want to get remote changes to the remote dev.

But I did a "git pull --rebase" which somehow removes the "master" remote in my "dev" branch.

Could you tell me how I can recover from my situation?

  • delete the changes that I push out of the remote "main" branch erroneously (after I did "git pull --rebase")

  • paste the changes into the remote branch "dev" on my branch "dev".

Thanks.

+4
source share
2 answers

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

 git config branch.dev.merge 

If refs/heads/master specified instead of refs/heads/dev , you can change the upstream branch for the dev branch with:

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

Then, to fix your branch, I would:

  • Make sure you are on dev branch with git checkout dev
  • Make sure git status clean.
  • Create a branch to save where you were (for security): git branch dev-wrongly-rebased
  • Use git reflog to find the commit before you reinstall it on origin/master
  • Reset dev to this point git reset --hard COMMIT-BEFORE-BAD-REBASE
  • Finally do git rebase origin/dev

My preference is when a reboot is always performed in two steps, for example:

 git fetch origin git rebase origin/dev 

... since I think it is less error prone than git pull --rebase . I hope this will be helpful.

+3
source

You can move commits on top of the correct remote branch with

 git rebase --preserve-merges --onto origin/dev start end 

for the range of commits given by the start and end, to move to dev.

Then configure tracking correctly. If you want, you can edit the .git / config file and compare how traffic is configured for each branch at the same time and ensure consistent behavior.

From now on, you get a new remote branch

 git checkout -t origin/branch_name 

Or if you push a new branch to the remote

 git push -u origin branch_name 

They will adjust the traffic as you wish.

Hope this helps.

0
source

Source: https://habr.com/ru/post/1343823/


All Articles