git push-pull-team-on-gitlab

13
rubytester presents. A Tale of Git Push and Pull” r why my push is rejected… Let’s say we have a ‘master’ branc with two commits on remote repo called ‘gitlab’ Notice in git graph arrow points to parent commit. It shows where commit came from. You want to clone it and make chan

Upload: rubytester-testrus

Post on 28-May-2015

1.186 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Git push-pull-team-on-gitlab

@rubytester presents.“A Tale of Git Push and Pull”or why my push is rejected…

Let’s say we have a ‘master’ branchwith two commitson remote repo called ‘gitlab’

Notice in git graph arrow points to parent commit.It shows where commit came from.

You want to clone it and make changes

Page 2: Git push-pull-team-on-gitlab

$ git clone #=> makes a ‘copy’ of git repository Gitlab is ‘remote’. You are ‘local’

you cloned remote locally

you have a perfect copyat the time you cloned.

Page 3: Git push-pull-team-on-gitlab

You make 2 new commits on top of a branch and you want to push it to ‘remote’

blue commits represent your workon your local repo. ‘remote’ does not know about it.

Page 4: Git push-pull-team-on-gitlab

$ git pushyour changes are pushed to ‘remote’ gitlab

Gitlab and you are exact copiesexact clones again.

Page 5: Git push-pull-team-on-gitlab

But you are not alone. There is always ‘them’, people on your team.

One of ‘them’ cloned gitlabat the same time that you cloned gitlab

Page 6: Git push-pull-team-on-gitlab

And they make commits and want to push as well. But they don’t know that ‘remote’ has changed

2 commitsfrom ‘them’planted onthe same parent nodeyour commitsare planted on

Page 7: Git push-pull-team-on-gitlab

Git rejects the push from ‘them’. ‘remote’ has changed because you pushed

Same parent node.Common ancestordivergent graphs

Page 8: Git push-pull-team-on-gitlab

‘They’ can not push. ‘They’ must fetch the changes first and integrate… But what should happen if ‘they’ git pull ???

$ git fetch brings changes from remote

Page 9: Git push-pull-team-on-gitlab

Default strategy is to merge on git pull. This creates a commit with ‘two parents’(merge or rebase here???)

Page 10: Git push-pull-team-on-gitlab

Now ‘they’ can ‘git push’ to gitlab. And you can integrated by ‘git pull’ But waitthere is more…

Page 11: Git push-pull-team-on-gitlab

They can ‘rebase’ on pull instead of merge. In this case ‘they’ replant 2 commits ‘as if’ they were based on diff parent

Page 12: Git push-pull-team-on-gitlab

And when ‘they’ push there will not be any ‘merges’. Just one line-of-work. (no superficial merges)

$ git config –global pull.rebase true #=> you can set this as your strategy

Page 13: Git push-pull-team-on-gitlab

Now when you pull you will have clean graph. The latest changes from ‘them’ are in your clone

Define Convention for team.rebase? Or merge?

‘Rebase’ when you pull from otherswhile developing a feature.

‘Merge’ when feature is done.

Avoid superficial ‘merges’

THE END@rubytester