29
push & pull options $ git kata Mateusz Grzechociński http://grzechocinski.net Other katas NOW (11:30) Katas NEXT (12:20) Git rebase (Wojtek Erbetowski) Manipulating commits (Jakub Nabrdalik) Submodules (Paweł Cesar Sanjuan Szklarz) Git flow (Michał Bareja) Configs/aliases (Jakub Nabrdalik) Refspec (Mateusz Grzechociński) Branches and tags (Mateusz Harasymczuk) Merging and rebasing (Mateusz Harasymczuk) Git filter-branch (Grzegorz Kubiak) USB workflow (Łukasz Siwiński) Rescue stash (Kamil Trzciński) Undoing changes (Marcin Zajączkowski)

Gitkata push and_pull_options

Embed Size (px)

Citation preview

Page 1: Gitkata push and_pull_options

push & pull options

$ git kata

Mateusz Grzechocińskihttp://grzechocinski.net

Other katas NOW (11:30) Katas NEXT (12:20)

Git rebase (Wojtek Erbetowski) Manipulating commits (Jakub Nabrdalik)

Submodules (Paweł Cesar Sanjuan Szklarz) Git flow (Michał Bareja)

Configs/aliases (Jakub Nabrdalik) Refspec (Mateusz Grzechociński)

Branches and tags (Mateusz Harasymczuk) Merging and rebasing (Mateusz Harasymczuk)

Git filter-branch (Grzegorz Kubiak) USB workflow (Łukasz Siwiński)

Rescue stash (Kamil Trzciński)

Undoing changes (Marcin Zajączkowski)

Page 2: Gitkata push and_pull_options

git fetch vs git pull

Page 3: Gitkata push and_pull_options

pull with fast forward=

no merge commit

Page 4: Gitkata push and_pull_options

pull without fast forward=

merge commit

Page 6: Gitkata push and_pull_options

git pull --rebase

Page 7: Gitkata push and_pull_options

git config --global branch.autosetuprebase always

Only for NEW branches

Page 8: Gitkata push and_pull_options

$ git checkout feature/securityBranch feature/security set up to track remote branch feature/security from origin by rebasing.Switched to a new branch feature/security

Page 9: Gitkata push and_pull_options

git config <branch_name>.rebase = true

For EXISTING branches

Page 10: Gitkata push and_pull_options

What about pushes?

● Let's checkout remote "new_feature" as "security"

● git checkout -t origin/new_fature -b security

● Let's try to push to "new_feature"

Page 11: Gitkata push and_pull_options

git push origin security

First try...

Page 12: Gitkata push and_pull_options

WRONG

Page 13: Gitkata push and_pull_options

"If :<dst> is omitted, the same ref as <src> will be updated."

... so new branch 'security' is created :(

Page 14: Gitkata push and_pull_options

Second try...

git push origin

Page 15: Gitkata push and_pull_options

WTF ???

Page 16: Gitkata push and_pull_options

The special refspec : (or +: to allow non-fast-forward updates) directs git to push “matching” branches: for every

branch that exists on the local side, the remote side is updated if a branch of the same name already exists on

the remote side.

... so all other branches were pushed unintentionally :(

Page 17: Gitkata push and_pull_options

Third try...

git push

Page 18: Gitkata push and_pull_options

WRONG

Page 19: Gitkata push and_pull_options

Works like git push <remote>, where <remote> is the current branch’s remote (or origin, if no remote is

configured for the current branch).

... so same as with 'origin' :(

Page 20: Gitkata push and_pull_options

Fourth try...

git push github HEAD

Page 21: Gitkata push and_pull_options

WRONG

Page 22: Gitkata push and_pull_options

git push origin HEADA handy way to push the current branch to the same name on the remote.

... but HEAD is resolved as security :(

Page 23: Gitkata push and_pull_options

Finally... use refspec!

git push security:new-feature

Page 24: Gitkata push and_pull_options

OK :)

Page 25: Gitkata push and_pull_options

What's the default behavior?

"By default, git push origin will update branches on the destination with one with the same name on the source, instead of using the association defined by git branch --track, which git pull origin would use — the config option push.default can change this behaviour.”

http://longair.net/blog/2011/02/27/an-asymmetry-between-git-pull-and-git-push/

Page 26: Gitkata push and_pull_options

git config push.default

● nothing ● matching (default)● upstream● current

Introduced 4 years ago in commit:https://github.com/git/git/commit/521537476fe99b97bfcdf1b8f0c579061af5fd3e

Page 27: Gitkata push and_pull_options

What should be by default?

● simple (not default)"push to the upstream branch, but only if it has the same name remotely. If not, give an error that suggests the right command to push explicitely to'upstream' or 'current'."

Introduced in commit: http://goo.gl/je6gkAvailable since 1.7.11 (https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.11.txt)

Ubuntu: [00:33:03] mgrzechocinski ~ git versiongit version 1.7.10.4

Page 28: Gitkata push and_pull_options

git push -u

● set tracking branch● set push branch$ git push origin -u topic/feature1Total 0 (delta 0), reused 0 (delta 0)To [email protected]:mgrzechocinski/gitkata.git * [new branch] topic/feature1 -> topic/feature1Branch topic/feature1 set up to track remote branch topic/feature1 from origin by rebasing.

$ git pushCurrent branch topic/feature1 is up to date.$ git pullCurrent branch topic/feature1 is up to date.