Skip to content

How to pull and merge 'development' into your working branch

sfiquet edited this page Mar 11, 2018 · 2 revisions

Since we are all working in parallel, it will often happen that changes are added to development on GitHub while you are busy working locally.

It is good practice to pull the latest version of development and merge it with your working branch before doing a PR. Here's how to do it.

Pulling and merging

1. Refresh the development branch

git checkout development
git pull origin development

2. Check out the working branch that you want to merge

This is necessary because merge always happens in the current branch.

git checkout <branch>

3. Merge with development

git merge development

Dealing with conflicts

In case of conflict git tells you that the automatic merging failed and where the conflicts are.

1. Check the list of problem files

git status

The files that can be merged are staged. The unstaged files are the ones you need to edit and/or remove.

2. Check and edit each problem file

Open the file in your favourite editor. The areas you need to edit are marked like this (example from merging package.json on the client):

<<<<<<< HEAD
  "proxy": "http://localhost:3001"
}
||||||| merged common ancestors
  "proxy": "http://localhost:3001"
}
=======
  "proxy": "http://localhost:3001",
  "devDependencies": {
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1"
  }
}
>>>>>>> development

The code between <<<<<<< HEAD and ||||||| merged common ancestors comes from your working branch.

Between ||||||| merged common ancestors and ======= is the code in the commit that is the common ancestor of the two branches (normally the version of development that you created your branch from).

Between ======= and >>>>>>> development is code coming from the development branch.

There can be several areas of this type in a single file. You can easily find them by doing a find of HEAD or <<<<

Your job is to compare the three versions of the code and decide what to keep. When you are done, the file should contain the final merged code with none of the merge markers.

3. Install new node modules if necessary

If package.json has changed in either the server or the client it is imperative to run npm install again to update the node modules before running any of the programs.

4. Run the tests

Make sure the test runner runs all the tests by pressing ‘a' in the test window.

5. Run the apps

Run the app as a whole and make sure it is doing what you expect.

6. Stage the files and commit

When all the files are merged and tested, you conclude the merge by staging the files and committing.

git add <files>

Note that you need to tell git to remove deleted files from the repo explicitly with:

git rm <file>

Finally commit with a clear message:

git commit -m “Merge with development"