=All about git=

Basic

create a new branch

$ git branch <name> 

switch to the branch

$ git checkout <name>

create a new branch and switch to it

$ git checkout -b <name>

merge from branch <name> to current branch

$ git merge <name>

remove branch

$ git branch -d <name>

show unstaged differences since last commit

$ git diff

add file to staging area

$ git add <filename>

view staged differences

$ git diff --staged

undo last commit, put changes into staging

$ git reset --soft HEAD^

change the last commit

$ git commit --amend -m 'New Message'

undo last commit and all changes

$ git reset --hard HEAD^

undo last 2 commits and all changes

$ git reset --hard HEAD^^

rename remote name

$ git remote rename <from> <to>

change url for remote

$ git remote set-url <name> <url>

list all remote branches

$ git branch -r

remote show

$ git remote show <name>

remove a remote branch

$ git push <name> :<branch>

tags

$ git tag # list all tags
$ git checkout <tag>
$ git tag -a <tag> -m 'tag message' # add a new tag
$ git push --tags # push new tags

change the author of commit

$ git filter-branch --commit-filter '
    if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
    then
        GIT_COMMITTER_NAME="<New Name>";
        GIT_AUTHOR_NAME="<New Name>";
        GIT_COMMITTER_EMAIL="<New Email>";
        GIT_AUTHOR_EMAIL="<New Email>";
        git commit-tree "$@";
    else
        git commit-tree "$@";
    fi' HEAD