Collection of intermediate but handy git tricks. This post will be updated now and then.

Apply patch from email

    git am -3 --signoff <name of patch>.patch

Bisect

<object id> could be master, 35f1cab or v1.4, for example.

    git bisect start
    git bisect good <object id>
    git bisect bad <object id>
    # test the given revision
    # say if it's bad or not with
    git bisect bad
    # continue this way and exit with
    git bisect reset

Branch off commit

    git branch new_branch <ref>

Commit part of diff from a file

    git add -p

Create emailable patch

    # edit
    # commit
    git format patch origin/master --stdout > my_changes.patch

Where origin/master is the base for references.

Discard parts of a diff

    git checkout -p
    # is hunk too big? 's' to split it

Merge commits

If you want to add some changes that you’d want included in the previous un-pushed commit

    git commit -am "just a commit"
    # make changes
    git commit --amend -a

Move hunk of commit to another commit

    git rebase -i HEAD~2
    # p ...
    # e ... <- edit this
    #edit files
    # git add; git commit --amend; git rebase --continue

Remove remote branch

    git push <remote> :<branch>

Show log with patches

    git log -p
    # for a specific file
    git log -p <path>