Git - Merge Strategies Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Fast forward merge

A

Fast forward merge works with a linear path from the current branch tip to the target branch. Instead of merging all git needs to do to integrate the histories is move (I.e. fast forward) the current branch tip up to the target branch tip.
This effectively combines the histories since all of the commits reachable from the target branch are now available through the current one.
This branch workflow is common for short lived topic branches with smaller changes.
If a master has not diverged instead of creating a new commit, it will just point point master to the latest commit of the hotfix branch. All commits from hotfix branch are now available in master

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Pulling via rebase

A

The —rebase option can be used to ensure a linear history by preventing unnecessary merge commits.
It is like saying “I want to put my changes on top of what everyone else has done”

Pulling with —rebase is such a common workflow that there is a dedicated configuration option for it:

git config - - global branch.autosetuprebase always

After running that command all git pull commands will integrate via git rebase instead of git merge.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Git pull in remotes

A

git checkout new_feature
git pull

This example first performs a checkout and switches to the branch.
Following that, the git pull is executed with being passed.
This will implicitly pull down the newfeature branch from .
Once the download is complete it will initiate a git merge.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Git pull rebase instead of merge

A

git checkout master
git pull - - rebase origin

The following example demonstrates how to synchronise with the central repository’s master branch using a rebase.
This simply moves your local changes into the top of what everybody has already contributed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a merge

A

Merging takes the endpoints and merges then together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When to rebase over merge

A

Rebase local changes you’ve made but haven’t shared yet before you push them in order to clean up your story but never rebase anything you’ve pushed somewhere

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Preparing to merge

A

Let’s assume you want to merge branch hotfix into your master branch

  1. Check your local repo is up to date with the latest changes from the remote server with a git fetch
  2. Once fetch is complete git checkout master
  3. Ensure the master branch has the latest updates by executing git pull
  4. Checkout to the branch that should receive the changes, in our case that is master
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Merging after preparations

A

Once prep is completed, you can start the merge with git merge hotfix command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Three way merge for diverged branches

A

When there is no linear way to a target branch, git has no choice but to combine them via three-way merge. This merge uses an extra commit to tie together the two branches.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to deal with merge conflicts

A

A merge conflict can arise when two branches you’re trying to merge both changed the same part of the same file. Git won’t be able to figure out which version to use.

e.g. if the file example.rb was edited on the same lines in different branches of the same git repository or if the file was deleted you will get a merge conflict error when you try to merge these branches.
Before you continue the merge conflict has to be resolved with a new commit.

Merge conflicts will only ever occur in the event of a 3 way merge.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to carry out a merge conflict

A
  1. Generate a list of the files which need to be resolved

git status

  1. When the conflicted line is encountered git will edit the content of the affected files with visual indicators that mark both sides of the conflicted content with:

««< conflict marker
===== divides your changes from the changes in the other branch
»»> end of conflicted lines

  1. Then decide if you want to keep only your hotfix or master changes or write a completely new code. Delete the conflict markers before merging your changes
  2. When your ready to merge all you have to do is run for add command on the conflicted files to tell git they are resolved.
  3. Commit your changes with git commit to generate the merge commit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Git fetch

A

Only downloads new data from a remote repository but it doesn’t integrate any of this new data into your working files.
Fetch is best for getting a fresh view on all the things happened in a remote repository.
Fetch will never manipulate or destroy anything.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly