git series. episode 2. merge, upstream commands and tags

35
Git Series. Episode 2 Merge. Upstream Commands. Tags Mikhail Melnik , 2015

Upload: mikhail-melnik

Post on 16-Jan-2017

313 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git Series. Episode 2

Merge. Upstream Commands. Tags

Mikhail Melnik, 2015

Page 2: Git Series. Episode 2. Merge, Upstream Commands and Tags

Merge

There are two types of merge:fast-forward and “true merge”.

Page 3: Git Series. Episode 2. Merge, Upstream Commands and Tags

Fast-Forward

Page 4: Git Series. Episode 2. Merge, Upstream Commands and Tags

Fast-Forward

Page 5: Git Series. Episode 2. Merge, Upstream Commands and Tags

Fast-Forward

Page 6: Git Series. Episode 2. Merge, Upstream Commands and Tags

Fast-Forward

OR

Page 7: Git Series. Episode 2. Merge, Upstream Commands and Tags

True Merge

Page 8: Git Series. Episode 2. Merge, Upstream Commands and Tags

True Merge

Page 9: Git Series. Episode 2. Merge, Upstream Commands and Tags

True Merge

Page 10: Git Series. Episode 2. Merge, Upstream Commands and Tags

Merge Summary

There are two types of merge:● fast-forward● “true merge”

Page 11: Git Series. Episode 2. Merge, Upstream Commands and Tags

Merge Summary

There are two types of merge:● fast-forward● “true merge”

Fast-forward is the default.Only when it fails, true merge is made.Should be explicitly set for merge!

Page 12: Git Series. Episode 2. Merge, Upstream Commands and Tags

PointersEvery local and remote branch

(master, origin/master, etc)is just a pointer to certain commit that in turn

points to certain data snapshot.

The same thing for tags.

HEAD is special Git word that represents a pointerto the current working tree state.

Page 13: Git Series. Episode 2. Merge, Upstream Commands and Tags

UpstreamsUpstream is a Git term describing the remote referenced object. For origin repo it means source repository it was cloned from. For local branch it means referenced branch from the remote repository.

You can watch these references using your favourite IDE or using a console Git command:git branch -v

There are also Git aliases for it: @{upstream} or @{u}. It’s possible to use following syntax:git fetch origingit checkout productiongit merge @{u} /* instead of ‘git merge origin/production’ */

Page 14: Git Series. Episode 2. Merge, Upstream Commands and Tags

Origin is an AliasAfter we do “git clone” we get a local copy of the remote repository that can be referenced locally using certain alias.

“Origin” is an default alias, representing repository if no other were set.

Similarly to it, “master” is the default name for the first branch in the newly created repository.

Page 15: Git Series. Episode 2. Merge, Upstream Commands and Tags

Origin is an AliasAll origin/* branches are not reachable directly, so you cannot modify them.

Instead you have local branches that were forked from one of the origin/* branches that really are not branches on the remote repository.

In fact, they are a remote branches copy that exist in your repository clone.

And that repository clone has a reference to the source repository.

Page 16: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git FetchFetch is a command for Git to update specified local repository with latest changes from its referenced upstream.

Page 17: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git FetchFetch is a command for Git to update specified local repository with latest changes from it’s referenced upstream.

Page 18: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git FetchFetch is a command for Git to update specified local repository with latest changes from it’s referenced upstream.

Page 19: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PullPull is actually a combination of fetch and merge. Pull fetches the new data to your repository and merges your current branch with it’s upstream.

Page 20: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PullPull is actually a combination of fetch and merge. Pull fetches the new data to your repository and merges your current branch with it’s upstream.

Page 21: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PullPull is actually a combination of fetch and merge. Pull fetches the new data to your repository and merges your current branch with it’s upstream.

Page 22: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git Pull

Important thing for pull isthat it merges (updates with changes)

only the current branch you are on.

Don’t forget to update other branchesafter switching to them!

Page 23: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PushPush is a command for Git to publish commits, that were made on local branches to their upstreams. Publishing changes does implicit fast-forward merge on the upstream repository.

Page 24: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PushPush is a command for Git to publish commits, that were made on local branches to their upstreams. Publishing changes does implicit fast-forward merge on the upstream repository.

Page 25: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PushPush is a command for Git to publish commits, that were made on local branches to their upstreams. Publishing changes does implicit fast-forward merge on the upstream repository.

Page 26: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git Push

By default, Git publish changesfrom all referenced branches.

Always explicitly specify the branchwhat changes you want Git to publish.

Page 27: Git Series. Episode 2. Merge, Upstream Commands and Tags

And Be Careful of Force Push

Page 28: Git Series. Episode 2. Merge, Upstream Commands and Tags

And Be Careful of Force Push

Page 29: Git Series. Episode 2. Merge, Upstream Commands and Tags

And Be Careful of Force Push

Never use --force (-f) flag without specifying a certain branch name!NEVER! Cause it may lead to data loss!

Page 30: Git Series. Episode 2. Merge, Upstream Commands and Tags

And Be Careful of Force Push

Whenever you do a force pushbe sure

you shout a loud to your team about it.

Page 31: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PushYou can set default behaviour for push in the Git settings.

Page 32: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PushThere are a bunch of push.default politics you can chose from:

● nothing — do not push anything unless a refspec is explicitly given.

● current — push the current branch to update a branch with the same name on the receiving end.

● upstream — push the current branch to the branch whose changes are usually integrated into the current branch (which is called @{upstream}).

● simple — works like upstream, but refuse to push if the upstream branch name is different.

● matching — push all branches having the same name on both ends.

Matching policy used to be the default until Git 2.0 came up.

Page 33: Git Series. Episode 2. Merge, Upstream Commands and Tags

Git PushBut I strongly recommend to be obvious and always set the branch name explicitly.

Page 34: Git Series. Episode 2. Merge, Upstream Commands and Tags

And Use the Tags

The simplest way to add new tag on current commit isgit tag v1.4

orgit tag -a v1.4 -m 'my version 1.4'

As it was said before in case of data/history losesyou can easily checkout your tag.

Of course if it wasn’t deleted by somebody :)