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?
remove the changes I pull in from remote 'master' branch mistakenly (after i did 'git pull --rebase')
pull in the changes on remote 'dev' branch on to my 'dev' branch.
Thank you.
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:
dev
branch with git checkout dev
git status
is clean git branch dev-wrongly-rebased
git reflog
to find the commit before you rebased onto origin/master
dev
to that point git reset --hard COMMIT-BEFORE-BAD-REBASE
git rebase origin/dev
My preference when rebasing is always to do it in two steps, eg:
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.
You can move the commits on top of the correct remote branch with
git rebase --preserve-merges --onto origin/dev start end
for a range of commits specified by start and end to be moved onto dev.
Then, set up tracking properly. If you want, you can edit the .git/config file and compare how traking is set up for each branch all at once and ensure consistent behavior.
From now on, of you are getting a new remote branch
git checkout -t origin/branch_name
Or if you are pushing a new branch to the remote
git push -u origin branch_name
These will set up traking as you want.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.