Saturday, October 24, 2026

Git cheatsheet

Differences between PR branch and the main Polaris branch:

git fetch --all
git diff upstream/main...origin/$FEATURE_BRANCH --name-only

Note the elipses. 

This is not the same as simply:

git diff upstream/main origin/$FEATURE_BRANCH --name-only

Rebase and merge do the same thing in different ways. Whereas merge splices two branches together, rebase rewrites the history to make it look as if there was no branch at all. This might mean that if you merge main onto your feature branch and then push it to the same feature branch, it may be reject even if you're the only person committing to that branch. This is because your local changes have different hashes to the remote. It's easily resolved with:

git push --force-with-lease origin $FEATURE_BRANCH

To rebase to main, the path should be:

git fetch origin
git switch $FEATURE_BRANCH
git rebase origin/main
git switch main
git pull --ff-only origin main
git merge --ff-only $FEATURE_BRANCH
git push origin main

Note that merge is a misnomer. It will act like a rebase.

The --ff is a fast-forward and will just move the branch pointer if there are no new commits to the branch to which your pulling. If there are, you'll need to merge like normal. On the merge, if there are changes, it will create a new commit.

No comments:

Post a Comment