Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Last active October 1, 2024 10:12
Show Gist options
  • Save devinschumacher/ea27f994d1be4e1cbf06f4735addae04 to your computer and use it in GitHub Desktop.
Save devinschumacher/ea27f994d1be4e1cbf06f4735addae04 to your computer and use it in GitHub Desktop.
How to do a "dry run" of a git merge to see what would happen without actually committing to it
title tags
How to do a "dry run" of a git merge to see what would happen without actually committing to it.
git
github
git merge
git diff

How to do a "dry run" of a git merge to see what would happen without actually committing to it.

Example: You have a local project, and you're on the local branch called dev. You haven't started working yet, but there may have been other activity since you originally cloned the remote dev branch, and you want to see how your branch compares to the remote dev branch so you can get in sync before starting to code - but you don't want to just git pull and risk conflicts, or losing info.

Run a git status to check the state of your project

git s

On branch dev
Your branch is up to date with 'origin/dev'.
  • Your on the dev branch
  • Your local project has no information that anything has changed.

Fetch any new activity from the remote

git fetch origin dev

Run a git diff to see the difference between your local dev branch and the remote:

# git diff <your-branch> <remote-branch>
git diff `dev` `origin/dev`

Dry run a git merge

git merge --no-commit --no-ff origin/dev

Automatic merge went well; stopped before committing as requested

Now run a git status to see the state of your project

git s
On branch dev
Your branch is behind 'origin/dev' by 5 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:
        new file:   content/_pages/test.md
        modified:   nuxt.config.ts
        modified:   package.json
        new file:   pages/[...slug].vue
        modified:   pnpm-lock.yaml

You can see there are some changes merged in (but not committed, so you can always go back easily)...

cmd+click the files to see them, for example the new file: content/_pages/test.md:

image

You like what you see... and want to get in sync with the remote.

Abort this "merge" you are doing, and then pull down the remote

git merge --abort

# git pull origin <branch>
git pull

title tags
How to do a "dry run" of a git merge to see what would happen without actually committing to it.

How to do a "dry run" of a git merge to see what would happen without actually committing to it.

Example: You're on a branch called some-branch and you want to see how your branch compares to your local dev branch.

  1. First run a git diff to see the difference between your branches:
# git diff <other-branch> <current-branch>
$ git diff dev some-branch
git merge --no-commit --no-ff dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment