Commits, reverts etc

Revert committed changes to a single file

$ git checkout <revision number to revert to> <file path>
$ git commit

Revert merge commit

git revert -m 1 [sha_of_merge_commit]

Correct commit message that hasn’t been pushed yet

git commit --amend
# Ref: https://help.github.com/articles/changing-a-commit-message/

Correct commit message after pushing to remote

git rebase -i HEAD~n
git push --force
# Ref: https://help.github.com/articles/changing-a-commit-message/

Branches

Delete remote branch

$ git push origin --delete <branch-name>

Rename local and remote branch

git branch -m old_branch_name new_branch_name
git push origin :old_branch_name
git push --set-upstream origin new_branch_name

Forks

Update fork from origin

$ git remote add upstream <remote-repo-url>
$ git fetch upstream
$ git checkout master
$ git pull
$ git merge upstream/master

Git submodules

Init and update submodules

$ git submodule init
$ git submodule update