Git

"Uncommit"

Undo not-yet-pushed commit:

Only undo the act of committing, leaving files added (staged):

git reset --soft HEAD^

Undo commit, and return files to be unstaged (unadded), files are intact:

git reset HEAD^

!!! Undo commit, and throw away (delete) all changes !!!

git reset --hard HEAD^

Reset local changes

To reset local (unstaged) changes:

git checkout -- .

Reset local branch to remote version

To reset local branch to be the same as remote:

git fetch origin
git reset --hard origin/branch-name

Rebase against master

To rebase branch agains master:

git checkout branch-name
git fetch origin
git rebase origin/master

If there are conflicts:

...
CONFLICT (content): Merge conflict in /path/to/file.php
...

$ vim /path/to/file.php

search for <<< or === or >>> and manually fix the ALL conflicts, save file

$ git add /path/to/file.php
$ git rebase --continue

rinse and repeat

To force push rebased branch back to origin:

git push --force-with-lease origin branch-name

Commit to wrong branch

if changes were not pushed yet:

git reset --soft HEAD^
git stash save
git fetch origin
git checkout correct_branch
git stash pop
git commit
git push origin correct_branch

Remove old local branches

Removes all local branches, which remote copies no longer exist (were merged)

git remote prune origin