empty initial commit
$ git commit --allow-empty -m "initial commit"
create a "blank" branch (coming from an existing branch)
and remove all files and directories in the current directory
$ git checkout --orphan newbranch
$ git rm -rf .
locally track a branch already on the remote
$ git checkout -b localbranch origin/remotebranch
remotely track a brand new local branch
$ git checkout -b localbranch
$ git push origin localbranch:remotebranch
same as above, but with simultaneous push
$ git push -u origin branchname
push only some commits to a new remote branch
~n
= skip the n most recent commits
$ git push origin localbranch~n:refs/heads/remotebranch
delete a remote branch
$ git push origin :branchname
delete a local branch
$ git branch -d branchname
update the branches shown for a remote
$ git remote prune origin
stop deleted remote branches from continuing to show up locally
$ git remote update origin --prune
for files already staged
$ git diff --cached
$ git diff --staged
individual files
$ git reset myfolder/myfile
edit commit message of last commit
$ git commit --amend
replace commit message of last commit
$ git commit --amend -m "new commit message"
change author of last commit
$ git commit --amend --author "First Last <[email protected]>"