TMDer / warehouse

code warehouse
http://tmder.github.io/warehouse/
10 stars 10 forks source link

git 實戰小知識 系列資料 #3

Open clonn opened 9 years ago

clonn commented 9 years ago

以下爲常用的小型知識

設定 user

git config (--global) user.name "your_name"
git config (--global) user.email "your@email"

設定 alias

git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global color.ui true
clonn commented 9 years ago

清除 git remote branch history

git remote prune origin

or

git fetch origin --prune

ref: cleaning up old remote git branches

malikid commented 9 years ago

Push/Pull/Fetch

Normal

git push (-u) origin [local_source_branch]:[remote_destination_branch]
git pull (-u) origin [remote_source_branch]:[local_destination_branch]
git fetch (-u) origin [remote_source_branch]:[local_destination_branch]

-u means setting default upstream, and is the abbreviation of --upstream.

Delete remote branch

git push origin :[remote_destination_branch]

Push an empty branch to a remote branch means to delete the remote branch.

Local Branch

Create branch and checkout that branch

git checkout -b [new_branch_name]

Track remote branch

git branch -u [remote_branch_to_be_tracked] ([local_branch])

-u means setting default upstream, and is the abbreviation of --upstream. Not specifying [local_branch] means the branch checkout now.

Rename branch

git branch -m ([branch_origin_name]) [branch_new_name]

Not specifying [branch_origin_name] means the branch checkout now.

Delete branch

git branch -D [local_branch]

Log

Log 出樹狀圖

git log --all --decorate --graph --oneline

從 Log 中搜尋 Commits 中的字串

git log (--all) --grep="string_to_search"

Commit

Modify most recently commit

git commit --amend

Merge

Merge other branch to the branch now

git merge [branch_which_merge_to_the_branch_now]

Rebase the branch now to other branch

git rebase [branch_which_the_branch_now_rebase_to]

Merge [commit_1] ~ [commit_n] to the branch now

git cherry-pick [commit_1] [commit_2] ... [commit_n]