Checks your Git version#
git --version
Settings your Git user name & email#
git config --global user.name "Andrew_Wu"
git config --global user.email "[email protected]"
Checks your configurations#
git config --list
Get Help#
git help <command> #get help for a git command
Creates a new git repo#
git init # create a new git repo, with data stored in the `.git` directory
Shows current repo status#
git status #tells you what's going on
Adds files to stage#
git add <filename> #adds seleted filename to stagin area
git add . #add all files to staging area
Creates a new commit#
git commit
git commit -m "commit message" #-m means Message
Shows a log#
git log #shows a flattened log of history
git log --all --graph --decorate #visualizes history as a DAG
Show changes#
git diff <filename> #show changes you made relative to the staging area
git diff <revision> <filename> #shows differences in a file between snapshots
Branch#
git checkout <revision> #updates HEAD and current branch
git branch #shows branches
git branch <name> #creates a branch
git branch -d <name> #deleted a branch
git checkout -b <name> #creates a branch and switches to it
same as git branch <name>; git checkout <name>
Merge#
git merge <revision> #merges into current branch
git mergetool #use a fancy tool to help resolve merge conflicts
git rebase #rebase set of patches onto a new base
git rebase -i HEAD~3 #modify history commit records
Remote#
git remote #list remotes
git remote add <name> <url> #add a remote
git push <remote> <local branch>:<remote branch> #send objects to reomote, and update reomte reference
git branch --set-upstream-to=<remote>/<remote branch> #set up correspondence between local and remote branch
git fetch #retrieve objects/references from a remote
git pull #Sync local and remote repos,same as git fetch; git merge
git clone #download repository form remote
Undo#
git commit --amend #edit a commit's contents/message
git reset HEAD <file> #unstage a file
git checkout -- <file> #discard changes
Advance#
git clown --depth=1 #shallow clone, without entire version history
git add -p #interactive staging
git blame #show who last edited which line
git stash #temporarily remove modifications to working directory
git bisect #binary search history (e.g. for regressions)
.gitignore #specify intentionally untracked files to ignore
References#
Version Control (Git)
Git 與 Github 版本控制基本指令與操作入門教學
Git教學 初心者懶人包 Git 入門