Skip to content

Git Workflow Examples

Shane Neuville edited this page Feb 19, 2025 · 3 revisions

Fixing Merge Conflicts on your PR

For MAUI pull requests (PRs), we prefer using rebase instead of merge. Rebasing creates a clean, linear commit history by applying your changes on top of the latest changes from the base branch. This approach avoids unnecessary merge commits, making the history easier to read, review, and debug. A clean history also simplifies operations such as bisects and rollbacks, leading to a smoother integration process.

1. Basic Rebase

To rebase your current branch onto another branch (e.g., main):

# Ensure you're on your working branch
git checkout feature-branch

# Ensure your 
git fetch origin

# Rebase onto main. 
git rebase origin/main

2. Rebase with --onto

Use --onto to rebase a series of commits from one branch onto a different base. This is useful when you want to move a branch starting from a specific commit to a new base commit.

Assume:

  • old-base is the commit where your branch originally diverged.
  • new-base is the target commit you want as a new starting point.
  • feature-branch is your branch with commits after old-base.
# Switch to the feature branch
git checkout feature-branch

# Rebase commits after old-base onto new-base
git rebase --onto new-base old-base feature-branch

3. Resetting Your Branch to the Remote

Sometimes you need to align your local branch with its remote counterpart. This can be done using a hard reset.

# Fetch the latest changes from the remote
git fetch origin

# Reset your current branch to the remote state
git reset --hard origin/your-branch

Be cautious: --hard discards any local changes.

4. Optional Git GUI Tools

For those who prefer a graphical interface, consider using these Git clients:

  • Fork: A fast and intuitive Git client that offers a rich set of features for visualizing your repositories. Learn more.
  • GitKraken: Provides a modern, visually appealing interface with advanced features to simplify your workflow. Learn more.
  • GitHub Desktop: A straightforward, GitHub-integrated tool ideal for managing repositories without the command line. Learn more.
Clone this wiki locally