Change branch base

Question

I've a tree like this:

(commit 1) - master
                \-- (commit 2) - (commit 3) - demo
                                                \-- (commit 4) - (commit 5) - PRO

and I have to move the PRO branch to master

(commit 1) - master
                |-- (commit 2) - (commit 3) - demo
                \-- (commit 4) - (commit 5) - PRO

I've tried a git rebase master from PRO branch, but nothing happens.

To clarify: I was working in master and then I had to make a product demo (git checkout -b demo and some commits). Then, by mistake, I create another branch from demo (git checkout -b PRO and some commits) and now I need to move PRO branch to master and leave demo intact. At the end, both demo and PRO will hang from master.

Answer

Assuming newBase is the branch you want to move your commits onto, oldBase is the old basis for your branch, you can use --onto for that:

git rebase --onto newBase oldBase feature/branch

Given your case:

git checkout PRO # Just to be clear which branch to be on.
git rebase --onto master demo PRO

Basically, you take all the commits from after demo up to and including PRO, and rebase them onto the master commit.

Where does the .gitignore file belong?

Check if pull needed in Git