1/15/2026Git

Advanced Git: Conflicts, Rebase, and PRs

Take your Git skills to the next level. Learn how to resolve conflicts, rebase branches, and manage advanced PR workflows.

Advanced Git: Conflicts, Rebase, and PRs

Advanced Git: Conflicts, Rebase, and PRs

Introduction

Once you're comfortable with the basics, it's time to tackle the scenarios that often scare developers: merge conflicts and rebasing.

What is a Conflict and How to Resolve It?

A conflict occurs when two branches have changed the same part of a file, and Git doesn't know which version to keep.

Steps to Resolve:

  1. Git will pause the merge and mark the files with conflicts.
  2. Open the file. You'll see markers like <<<<<<< HEAD and >>>>>>> feature-branch.
  3. Manually edit the code to keep the correct changes.
  4. Remove the markers.
  5. Add the file and commit:
    git add filename.ext
    git commit -m "Resolved merge conflict"
    

What is Rebase?

Rebasing is an alternative to merging. Instead of creating a "merge commit" when you combine branches, rebase effectively "moves" your branch to begin from the latest commit of the target branch. This keeps the project history linear and clean.

Command:

git checkout feature-branch
git rebase main

pull --rebase: The Shortcut

When you pull changes from the remote, Git defaults to a merge strategy, which can create messy "Merge branch 'main' of..." commits. Using git pull --rebase avoids this. It fetches the changes and then replays your local commits on top of them.

Tip: You can set this as default globally:

git config --global pull.rebase true

Boost Your Productivity with Shortcuts

Typing long git commands can be tedious. You can use aliases to speed up your workflow. Check out this handy repository for a collection of pre-made shortcuts.

Examples:

  • gs -> git status
  • gaa -> git add .
  • gc "msg" -> git commit -m "msg"
  • gp -> git push

One-Line Install:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/kksingla/CodingTips/main/install-git-shortcuts.sh)"

Advanced PR Workflows

Raising a PR isn't just about clicking a button.

  • Draft PRs: Create a PR as "Draft" if it's work-in-progress. This signals "don't merge yet" but allows early feedback.
  • Code Owners: Use a CODEOWNERS file to automatically assign reviewers based on which files were touched.
  • CI/CD Checks: Ensure your PR passes all automated tests before asking for a review.