How to get latest commit to be pulled for a PR?

31 Views Asked by At

While creating the GitHub Pull Request between the branches, it's taking the previous commit on the target branch instead of the latest one.

As a result, we are unable to complete the deployments, leading to a lot of manual changes on the branches to resolve the conflicts.

1

There are 1 best solutions below

0
VonC On

You need to make sure your feature branch is up-to-date with the target branch.

Feature Branch                        Target Branch
      │                                      │
      ├─ ● Commit A                          ├─ ● Base Commit
      ├─ ● Commit B                          ├─ ● Commit X (Old)
      │                                      ├─ ● Commit Y (New)
      │ (fetch & merge/rebase here)          v
      v          

That should involve fetching the latest changes from the target branch and merging or rebasing your feature branch against it before creating or updating the PR.

git fetch origin
git switch your-feature-branch

git merge origin/target-branch
# or, to keep a cleaner, linear history
git rebase origin/target-branch

If you encounter conflicts during the merge or rebase, you will need to resolve them manually, then continue the rebase (if you are rebasing) or commit the merge (if you are merging).

Feature Branch                          Target Branch
      │                                      │
      ├─ Base Commit                         ├─ Base Commit
      ├─ Commit X (Old)                      ├─ Commit X (Old)
      ├─ Commit Y (New) ── merge/rebase ──>  ├─ Commit Y (New)
      ├─ Commit A                            v
      ├─ Commit B
      v

Push your changes to the feature branch on the remote repository. If you have rebased, you will need to use force push:

git push origin your-feature-branch --force

That will make sure your feature branch contains all the updates from the target branch, allowing for a cleaner and conflict-free PR.