Skip to content

Instantly share code, notes, and snippets.

@nfx
Last active November 24, 2023 11:28
Show Gist options
  • Save nfx/04eac94612dc85648e83652e6ecbaf54 to your computer and use it in GitHub Desktop.
Save nfx/04eac94612dc85648e83652e6ecbaf54 to your computer and use it in GitHub Desktop.
git commands

Some commands are repeated so often, but one may forget the exact syntax

Squash all commits on branch

From this stackoverflow comment:

git reset $(git merge-base $(git config --get init.defaultBranch || echo main) $(git branch --show-current)) && git add -A && git commit

Squash and rebase

git reset $(git merge-base $(git config --get init.defaultBranch || echo main) $(git branch --show-current)) && git add -A && git commit && git fetch && git rebase origin/$(git config --get init.defaultBranch || echo main) -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment