My Digital Garden

Git Cheat Sheet

Git Cheat Sheet

Some useful commands

An empty initial commit

git commit --allow-empty -m "Initial commit"

Git log options

Show graphical branches

git log --oneline --decorate --graph

Branch subtleties

Delete locally:

git branch -d <branchname>

or, to force if branch not pushed:

git branch -D <branchname>

Delete remotely:

git push origin --delete <remoteBranchName>

or,

git push origin :<remoteBranchName>

Merges and rebases

Reword commit message of a merge:

git checkout <sha of merge>
git commit --amend # edit message
git rebase HEAD previous_branch

See also