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

Post on 16-Jan-2017

313 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Git Series. Episode 2

Merge. Upstream Commands. Tags

Mikhail Melnik, 2015

Merge

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

Fast-Forward

Fast-Forward

Fast-Forward

Fast-Forward

OR

True Merge

True Merge

True Merge

Merge Summary

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

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!

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.

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’ */

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.

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.

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

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

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

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.

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.

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.

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!

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.

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.

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.

Git Push

By default, Git publish changesfrom all referenced branches.

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

And Be Careful of Force Push

And Be Careful of Force Push

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!

And Be Careful of Force Push

Whenever you do a force pushbe sure

you shout a loud to your team about it.

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

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.

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

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 :)

top related