Here is my situation
- I checkout from main and make my feature branch “my branch “
- I pushed my changes into remote “my branch”
- Main got advanced with few merges from other people
- Now I have worked more on my local branch , and want to do following
- “ take all the changes of remote main , and put my local branch changes in top of them “
- I have tried doing git rebase and pull but doing that just overwrite my local files and They are left with errors due to weird mismatch ( from my local and remote ) . Luckily I have staged and committed so no changes are lost
CodePudding user response:
For this, you cannot do a pull. You did have the right idea though:
git rebase main
Then when locally everything is in order, force push (git push --force
) to overwrite the remote "my branch", telling it that your state (which includes the commits added from main) is the correct one.
CodePudding user response:
Lets say we have master, branch_A (made from master) and branch_B (also made from master). I am working on branch_A and my friend is working on branch_B. My friends work in branch_B was merged to master. Now I am done and I want to merge my branch to master as well. The process I would follow is below:
- git checkout master
- git pull (update local master from with remote changes)
- git checkout branch_A
- git rebase master (this will pull in the changes from master and stack your branch commits on top)
- git push origin branch_A -f (need force since you rebased which changes branch HEAD)
Hope that helps.