Skip to content

Git setup

Posted on:May 29, 2024 at 07:28 AM

Boost your git

# add alias
# usage: `git alias` to list all alias
git config --global alias.alias "config --get-regexp ^alias"
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.cm commit -m
git config --global alias.br branch

# quick push
# usage: `git push` can automatically track a remote branch with the same name of local branch
# example: branch chao/dev => git push => branch origin/chao/dev 
git config --global push.default current
git config --global push.autosetupremote true

Git quick command

Understand git

Working tree vs. Index

Untitled.png

Distinguish git reset / git checkout / git restore

# Reset HEAD to <commit>, store modifications in working tree
git reset --soft <commit>

# Reset HEAD to <commit>, dump all modifications
git reset --hard <commit>

--soft
Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

If -N is specified, removed paths are marked as intent-to-add (see git-add[1]).

--hard
Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded. Any untracked files or directories in the way of writing any tracked files are simply deleted.
git clean
# -d: directory
# -f: force
# -n: dry run