Search code examples
gitgithub

Creating new branch results in PR using old code for base branch


I have a feature branch were the work has been completed, but it is still going through PR. I am doing some additional work on that code and thus created a second branch based off that code. I used to the following method to create that branch.

git checkout feature/baseBranch
git checkout -b feature/newFeatureBranch

When I commit this newFeatureBranch to github and do a PR with no code changes whatsoever, it shows a bunch of changes. It seems that the base code being used has none/few of the changes to the base branch such as the next sprint being pulled in.

I have no idea why this is happening or how to fix it. I can confirm that the code it is using for the base branch is old and not valid. I have tried repulling the code from the sprint and even though it says the code is up to date, that isn't reflected in the PR.

There are also a lot of commits in the new feature/newFeatureBranch that seem to come from the base branch. This is with zero commits on the newly formed branch.

I'm at a loss.


Solution

  • Let's get you synchronized with GitHub. First, close the problematic PR at GitHub (if you actually opened it). Then, on your machine:

    git fetch
    git switch -c feature/newBaseBranch origin/feature/baseBranch
    git push origin feature/newBaseBranch
    

    Now, on GitHub, start to make a new PR and specify that you want to merge into feature/baseBranch from feature/newBaseBranch. (I state the branch names in that order because that is the order in which GitHub presents them to you, a thing I've always found rather confusing.)

    GitHub should respond that there are no differences between the two branches and there is nothing to do. You should then be confident that it's okay for you to start adding and committing to your local feature/newBaseBranch.

    Note that if, as you work, the existing PR from feature/baseBranch gets approved and merged into main, the new PR (if you actually created it) will be repointed to be merged into main as well, automatically.