Git push的Matching與Simple

當git push沒有指定branch時,設定Matching或Simple會有什麼差別?

自從我把Mac OS 從10.7升級到10.9後,Git的版本也因此從1.7升級到了1.8.3.4,在每次要使用Git做push的動作時,都會跑出這個警告。
warning: push.default is unset; its implicit value is changing in
Git 2.0 from ‘matching’ to ‘simple’. To squelch this message
and maintain the current behavior after the default changes, use:
git config —global push.default matching
To squelch this message and adopt the new behavior now, use:
git config —global push.default simple
See ‘git help config’ and search for ‘push.default’ for further information.
(the ‘simple’ mode was introduced in Git 1.7.11. Use the similar mode
‘current’ instead of ‘simple’ if you sometimes use older versions of Git)
但卻是有看沒有懂,可是Push並沒有失敗,我就沒有急著去找出為什麼XD

直到最近我看到了這篇文章,才了解到原來這是因為為改版後,git push可以設定成兩種模式:simple、matching。

主要的差異

當使用git push指令時,後面如果沒有指定branch時,設定Matching或Simple會有不同的結果。

Matching

這是在改版前預設的做法,它會push所有本地端跟伺服器端已經設定為upstream的braches。

Simple

它只會push當下所在的branch,並不會push其他的branches。


設定你的預設

設定好其中一種你想使用的push模式,它就不會再出現這個警告了!
git config --global push.default matching
就我個人來說,當我git push沒指定branch時,通常只想push當下所在的branch,所以個人建議設定為simple模式。
git config --global push.default simple


最後

如果你設定為Simple之後,有想要一次push所有branches的情況,只要在後面加上--all就好了!
git push --all

留言

這個網誌中的熱門文章

【Mac】提升工作效率必備APP-Alfred

Android的SQLite版本問題