Quando faccio git push quali branch sto pushando?

Lavorando in command line in Git si potrebbe erroneamente pensare che facendo un

git push

Si effettui il push della sola branch che è in checkout, ma questo non è vero, dato che il reale comando per effettuare il push di una branch è

git push remotename branchname

Quindi se state nella branch XYZ ed avete un  unico remote chiamato origin dovete fare

git push origin XYZ

Il comportamento adottato da git se non specificate ne il remote ne la branch è determinato dalla impostazione push.default e come possiamo leggere dalla documentazione le possibilità sono.

nothing – do not push anything.

matching – push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.

upstream – push the current branch to its upstream branch.

tracking – deprecated synonym for upstream.

current – push the current branch to a branch of the same name.

Il default è matching, per cui facendo un git push state effettuando il push di tutte le vostre branch. Questa opzione probabilmente non è il miglior default che si possa avere, per questo in Git 2.0 il default verrà modificato in “Simple”, un ulteriore nuovo possibile valore per push.default:

simple – in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one. When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners. This mode has become the default in Git 2.0.

Fate quindi attenzione al modo che avete selezionato per evitare sorprese.

Gian Maria.

Comments are closed.