Quick Git Hints (Work-In-Progress)

A compilation of Git commands I have found useful so far:

  • Merge multiple pushed commits, and push to remote

    For example, for 4 most recent commits:

    git rebase --interactive HEAD~4

    In interactive dialog, squash (merge) commits 2-4 - by replacing “pick” with “squash”

    Save session (e.g :wq in vi), and choose new commit message. Then:

    git push origin +master

  • Highlight word changes

    This only highlights the changed words, nicely inline. Try:

    git diff --word-diff

  • To quickly discard unstaged changes:

    git stash save --keep-index
    git stash drop

  • My ~/.gitconfig file - explanations can be found in individual commits to my github repo.