> >
git log
git log --abbrev-commit
git log --graph
git shortlog
git reflog
# create a new branch
git checkout -b branch-name
# equivalent to
git branch branch-name
git checkout branch-name
# checkout to an existed branch
git checkout branch-name
# to last branch
git checkout -
# create an orphan branch
git checkout -b --orphan branch-name
git rev-parse --abbrev-ref HEAD
git remote add upstream <ORIGINAL>
git fetch upstream
git merge upstream/master
git clone https://username:password@remote
git checkout master
git reset --hard upstream/master
git push --force
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch /path/to/data' \
--prune-empty --tag-name-filter cat -- --all
git commit --amend
# Reset commit author
git commit --amend --reset-author
# Rebase
git rebase -i HEAD~n
git push --force
# Set origin (fetch)
git remote set-url [url]
# Set origin (push)
git remote set-url --push [url]
git fetch origin pull/[pr_id]/head:[branch-name]
git remote add pr [url]
# edit and commit
git push pr HEAD:[branch-name]
git clean -f -d
git checkout HEAD^ /path/to/file
--soft
)--hard
)# Cancel `git add`
git reset HEAD
# Cancel last commit
git reset HEAD~
# Remove file from last commit
git reset HEAD /path/to/unwanted_file
git commit -c ORIG_HEAD
# Reset workspace (BE CAUTIOUS)
git reset --hard
# or
git checkout .
Difference between HEAD^ and HEAD~
git stash
git stash apply
git stash drop
git stash pop # like apply and then drop
git stash list
gid add --patch /path/to/file
# Then select the hunks
git revert -m 1 <merge-commit-hash>
# create tag
git tag tag-name
git push origin tag-name
# delete tag
git tag -d tag-name
git push --delete origin tag-name
# rename tag
git tag new old
git tag -d old
git push origin new :old