On Github I have:
github_master_branchand a personal (remote) branch, let's say it github_personal_branch
In the past I cloned from github
I checked out github_personal_branch (using Pycharm) and created a local branch, with the same name (but let's say it's local_personal_branch)
From the local_personal_branch I push to the github_personal_branch
Now, on github_personal_branch, I have commits behind and in front of github_master_branch.
I want to get the changes from github_master_branch to my
local_personal_branch, fix the conflicts and then push it to the
github_personal_branch.
I tried to rebase, but instead I got a lot of commits, all the ones the github_master_branch was ahead, instead of moving header.
I also tried the rebase option in Pycharm, multiple combinations, but I don't understand very well the onto, from fields logic.
I tried a second manual rebase, but besides master I got very old code, that was available some time ago on the local_personal_branch.
To rebase in Pycharm, you need to make sure you are first on the right branch:
local_personal_branchoriginrefs/remotes/origin/github_master_branch (onto field), as described here
Rebase requires force push anyway, btw it's not a good way neither to force push, neither to rebase.
I would argue that, in this case, it is: a "local_personal_branch" is personal (to you): you can rebase it and force push it as many time as you want, since you are the only one working on it.
The idea of a rebase is making a future pull request trivial to accept, because your local_personal_branch commits will have been rebased on top of the latest of origin/github_master_branch, which means accepting such a PR would result in a simple fast-forward merge: no conflicts.
Plus, as mentioned here, merging master into a feature branch is not considered as a best practice: you (generally) merge to master, not from it.
See "rebase vs. merge".
While I am quite experimented with CLI rebase, I never grasp how to use the rebase option of IntelliJ ^^
From what I understand you have the following setup:
github/master
v
A-B-C---D-E
\
\-F-G
^
personal,
github/personal
You should have a master branch (local master) somewhere too. If you are not sure of this setup, please provide us the output of the following command:
git log --oneline --decorate --graph local_personal_branch github_personal_branch master github_master_branch
What you want is to rebase you personal branch onto master to get the following graph:
github/master
v
A-B-C---D---E---F'---G'
^
personal
github/personal
So the command is:
git rebase --onto github/master C personal
git push --force
To explain it:
C and the personal to be put onto the current github/master branch.For information, your remote repository is probably called origin and not github (see the output of git remote -v) and so you should replace reference to github by origin in the previous commit. The C letter must be replaced by the hash number of the last common commit between master and personal.
Kind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With