Update with latest changes to main branch (git rebase)


      This file relates to both  GitHub and  GitLab.
    

The following guide shows you how to update your current branch with code from another branch that may have more commits since you have branched off it
This is extremely useful in the case where you may be working on your own branch and in the meantime the master branch has been updated. By rebasing, you are able to test your code against the latest code as well as preemptively ensuring that your PR will not fail to merge. Console usage is required

Speaking of which, if your PR fails to merge, rebase your branch against the parent branch you are merging your branch to (should be the master branch) and push your branch again (check the "Force Push" checkbox in the Push window if it fails to push)

  1. Ensure that your parent branch you are rebasing your current branch off is updated (See Update branch)
  2. Ensure that your branch is selected and click the Terminal button
    Rebase Commit #1
  3. Execute the following command
    git rebase "branch name"
    , replacing "branch name" with the name of the branch you are rebasing from (in the case of the picture below, it is the master branch we are rebasing from)
    Rebase Commit #2
  4. If you have no merge conflicts you are done! Otherwise look at Resolving Merge Conflicts to resolve any conflicted code
Demo Video
The following is a video on how this is being done. Read the how-to guide before watching the video for actual steps to do it

Console Commands Used

      git fetch origin # Fetches from origin (replace origin with your remote)
      git checkout "branch" # Checks out the branch
      git pull # pulls the branch
      git checkout "yourbranch" # Go back to your branch
      git rebase "branch" # Rebase against the other branch