git init:Initialized a repository for specific folder. Initialized empty Git repository in /.git/

git status:check current status of git and see other infomations.

git help:help info.

git help config:show “config” command info.

git config --global "Carlos Chang":who gets credit for changes.

git config --global "":What email you use.

git config --global color.ui true:Pretty command line colors.

git config --list:list all configs.

如果遇到這個問題:Could not execute editor
// 設定 git 的編輯器路徑:
git config –global core.editor “/usr/bin/vim”

git add sample.txt:add sample.txt into staging and start tracking.

git add "*.txt":add all txt files in the whole project.

git add --all:add all files.

git add -A

git add docs/*.txt:add all txt files in docs directory.

git add docs/:add all files in docs directory.

git commit -m "Add cute octocat story":let staged files into repository

git commit -a -m "Modify readme":Add changes from all tracked files.

git commit --amend -m "Modify commit message"--amend 更改目前已 commit 的訊息

git log:browse all commits we had changed.

# git log --oneline:log in one line.(會顯示部份的 commit id)

# git log --decorate:會多顯示 branch 的位置,包含遠端的。

# git log --pretty=oneline:log in one line.(會顯示完整的 commit id)

git log --pretty=format:"%h %ad- %s [%an]":format your log data.

git log --oneline -p:-p means patch

git log --oneline --stat

# git log --oneline --graph:顯示精簡的圖,visual representation.

# git log --oneline --graph:顯示完整的圖

# git log -3:顯示最新 3 筆的 commit。

# git log --after="yesterday":顯示從昨天開始到現在的 commit。

# git log --after="30 minutes ago":顯示 30 分鐘內的 commit。

# git log --after="3/15/16" --before="yesterday"

# git log --since="3/15/16" --until="yesterday"

# git log --author="Carlos":顯示 Carlos 的 commit。
# git log --author="Carlos\|Jane":顯示 Carlos 或 Jane 的 commit。

# git log --grep="modified conflict":會從 commit message 當中,抓取有 “modified conflict” 字串的 commit。

# git log -S"the_test":抓取程式碼中有改變 the_test 字串的 commit。
# git log -p -S"the_test":同上,只是會直接多呈現出程式碼改變的地方。(-p 代表 patch)

# git log -Gthe_test
# git log -p -Gthe_test
# git log -Gthe_test\|another_search_string

# git log -i --author="carlos":-i 會忽略大小寫,抓取有 carlos 的 commit。

# git log --no-merges

# git log master..another_branch:顯示這兩個 branch 之間的 commit。

# git log看某個檔案的log。

git remote add <name> <address>:To add new remotes. “add” means new remote; “origin” means our name for this remote; “” means address.
git remote add origin
git remote add origin

git remote -v:show remote repositories.
# git remove -v
origin (fetch)
origin (push)

git remote rm <name>:To remove remotes.

git remote show origin:show descriptions about local branches with remote branches.

git remote prune origin:To clean up deleted remote branches.

git push -u origin master:The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.

git push -u <name> <branch>:To push to remotes.

git push:to push everything you’ve been working on to your remote repository.

git push origin shopping_cart:push an new branch to remote origin.(Links local branch to the remote branch(tracking))

git push origin :shopping_cart:Deletes remote branch.

git push heroku-staging staging:master:Will push and deploy staging on heroku.

git pull origin master:pull remote origin remote and master branch down to merge.

git pull:to pull changes down from the remote.

git fetch:Fetch(or sync) our local repository with the remote one.

git diff:show unstaged differences since last commit.

git diff HEAD:what is different from our last commit by using the git diff command. The HEAD is a pointer that holds your position within all your different commits. By default HEAD points to your most recent commit, so it can be used as a quick way to reference that commit without having to look up the SHA.

git diff --staged:go ahead and run git diff with the –staged option to see the changes you just staged.

git diff --stat:顯示差異的統計結果。

git diff --cached:顯示未 commit 的(但已經有進入stag階段的)與最後一個 commit 的差異。

git reset octofamily/octodog.txt:unstage files by using the git reset command.

git reset HEAD octodog.txt:to unstage files. HEAD means refers to last commit.

git reset --soft HEAD^:–soft means “Reset into staging”; HEAD^ means “move to commit before HEAD”.

git reset --hard HEAD^:–hard means “Undo last commit and all changes”; HEAD^ means “move to commit before HEAD”.

git reset --hard HEAD^^:–hard means “Undo last commit and all changes”; HEAD^^ means “move 2 commit before HEAD”.

git checkout -- octocat.txt:Files can be changed back to how they were at the last commit by using the command. Blow away all changes since last commit.

git checkout clean_up:switch branch to clean_up branch.

git checkout -b admin:switch to a new branch ‘admin’.(creates and checks out branch)

# git checkout –:是一個 shortcut,可直接切換到剛才的 branch。

git checkout v0.0.1:check out code at commit.(v0.0.1 is a tag)

git branch clean_up:new a branch called clean_up.

git branch:list all branches now.

git branch -d clean_up:delete clean_up branch.

git branch -D clean_up:force to delete clean_up branch.

git branch -r:list all remote branches.

git rm '*.txt':remove all those pesky octocats by using the git rm command which will not only remove the actual files from disk, but will also stage the removal of the files for us.

git merge clean_up:merge clean_up branch into current branch.

git merge origin/master:merges origin/master with master.

# git clone into ‘git_test’…(會新增 test_git 資料夾)

# git clone git_demo:Cloning into ‘git_demo’…(會新增 git_demo 資料夾)

git tag:list all tags.

git tag v1.0.0:新增 v1.0.0 這個tag。

git tag -a v0.0.3 -m "version 0.0.3":To add a new tag.

git push --tags:To push new tags.

git rebase:1、Move all changes to master which are not in origin/master to a temporary area.2、Run all origin/master commits.3、Run all commits in the temporary area, one at a time.(No Merge Commit!)

git rebase master:local branch rebase.

git rebase --continue:when you have resolved this problem.

git rebase --skip:If you would prefer to skip this patch, instead run this.

git rebase --about:To checkout the original branch and stop rebasing run this.

git rebase -i:進入 rebase 的互動編輯視窗, -i 是 interactive 的意思。

git rebase -i origin/master:進入 rebase 的互動編輯視窗,與 origin/master 當基準。

git blame a.js --date short:顯示誰改了哪一行

git blame a.js:顯示誰改了哪一行,與上同,但資訊較完整。

# git stash:封存目前修改的。

# git stash apply:將封存的東西,回覆到當前的 branch。