This post is about the git commands that I find hard to remember.
git add
Add Tracked Files Only
Move Last Commits To A New Branch
View on StackOverflow
git checkout
Checkout A Remote Branch
Discard Unstaged Changes
Discard changes with new files:
View on StackOverflow
git clone
git commit
Change Author After Commit
Reference GitHub Commit
git config
Prevent GitHub git bash from Asking for Password
Change remote to be SSH instead of HTTPS.
Colorful UI
Alias
So that I can use git ck
instead of git checkout
later.
Setup email and name
git diff
View Changes After Commit
Before committing, changes can be viewed by git diff
. But if you forget to check it before committing, this is what you can do.
View Changes of A Commit
To view the change of a specific commit, use
View Changed Line Counts
git diff-tree
View Files Changed in A Commit
To list the files changed in a commit, use
git log
View Remote Commit Log
E.g., git log origin/master
.
View on StackOverflow
Search in Commit Log
git merge
Undo unpushed merge
Merge without New Commit
git push
Delete A Remote Branch
Push To A New Remote Branch
Delete A Remote Tag
git remote
Add Remote
Show Remote URL
Change Remote URL
git reset
Undo Unpublished Commits
Undo Published Commits
Undo A Commit
After commit, to undo the commit, use:
Undo Uncommitted Changes
For tracked files and directories:
For untracked files and directories:
Revert to Last Remote Commit
git revert
Revert Pushed Commit
git show
View Files of Last Commit
Or, redirect it to a file.
View on StackOverflow
git update
Ignore tracked local file
Corresponding undo operation is as follows.