On Github kdheepak89 / think-like-a-git
Note: speaker notes FTW!
git config --global user.name "<name>"
git config --global user.email "<email>"
git config --global color.ui auto
.gitconfig
git clone ssh://user@domain.com/repo.git
git init
git init <project-name>; cd <project-name>
git status
git show <commit-hash>
git diff
git diff --staged
git diff --cached
git diff <branch-name-1> <branch-name-2>
git diff <commit-hash-1> <commit-hash-2>
git diff <commit-hash-1> <commit-hash-2> -- <file-name>
git diff --stat origin/master
git add <new-file-name>
git add .
git add -p <file-name>
git rm <file-name>
git rm --cached <file-name>
git mv <file-name> <new-file-name>
git commit -a
git commit
git commit -m <message>
git commit --amend
git commit --amend -m <message>
git stash
git stash pop
git stash list
git stash drop
git log
git log -p <file-name>
git blame <file-name>
git log --graph --abbrev-commit --decorate --color=always --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) - %C(dim red)%an%C(reset)%C(bold yellow)%d%C(reset)' --all
git branch
git checkout <branch-name>
git checkout -b <new-branch-name>
git branch <new-branch-name>
git branch --track <new-branch-name> <remote-branch-name>
git branch -D <local-branch-name>
lists branches merged into master git branch --merged master
# lists branches merged into HEAD (i.e. tip of current branch) git branch --merged
# lists branches that have not been merged git branch --no-merged
By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.
git push <remote-name> <remote-branch-name> --delete
git tag <tag-name>
git merge <branch-name>
git remote show <remote-name>
git remote -v
git remote show <remote-name>
git remote add <remote> <url>
git remote set-url <remote-name> git@github.com:<user-name>/<repo-name>.git
git fetch <remote>
git pull <remote-name> <branch-name>
git push --dry-run
git push <remote-name> <branch-name>
git push -u <remote-name> <branch-name>
git push <remote-name> :<branch-name>
git push <remote-name> --force
git push --tags
git merge <branch-name>
git rebase <branch-name>
git rebase --abort
git rebase --continue
git rebase -i <branch-name>
git mergetool
git add <resolved-file-name>
git rm <resolved-file-name>
git reset --hard HEAD
git checkout HEAD <file-name>
git revert <commit-hash>
git reset --hard <commit-hash>
git reset (--mixed) <commit-hash>
git reset --soft <commit-hash>
This works because 'reset' copied the old head to .git/ORIG_HEAD. If you don't need to edit the old message, use -C instead of -c.
git commit -c ORIG_HEAD
git reset --keep <commit-hash>