Boris Boris - 1 month ago 13
Git Question

Using Terminal how to merge my branch to team master without ugly merge info

I have my develop branch and I have written some code while the master branch is also developing.

Now I finished my module and would like to merge it to master branch but I set my git like this:

$ git config --global merge.ff only


Now when I try to merge, it gives

fatal: Not possible to fast-forward, aborting.


So what commands I should do in
Terminal
to merge it successfully and with no ugly merge info on the log.

Please be specific, many thanks.

Answer

I will use an example to illustrate some alternatives.

Assume you have made the following two "Develop commit" commits on the develop branch, while there were two commits being made to the master branch:

* c302cd7 - (HEAD, develop) Develop commit 2
* 0a1fad1 - Develop commit 1
* fcf19a0 - Common commit

Alternative 1: git merge

Merge develop into master. Ie.:

git checkout master
git merge develop

This would result in a history looking like this:

*   e33bcaf - (HEAD, master) Merge branch 'develop'
|\  
| * c302cd7 - (develop) Develop commit 2
| * 0a1fad1 - Develop commit 1
* | 784442c - Master commit 2
* | 03c7803 - Master commit 1
|/  
* fcf19a0 - Common commit

As I understand, you do not want this. You want to avoid the merge commit (e33bcaf in the example above)

Alternative 2: git merge --squash

This approach will take all the changes from the develop branch and bundle them together into one squash commit.

git checkout master
git merge --squash develop
git commit
#enter apporpriate commit message describing the changes from develop branch

History will look like:

* 2fd2acc - (HEAD, master) Develop branch squash commit
* 784442c - Master commit 2
* 03c7803 - Master commit 1
* fcf19a0 - Common commit

Alternative 3: git rebase

You can let git try to reproduce the same changes that you made on the develop branch, but starting from the latest version of the master branch instead. Note that this is not a good idea if develop is a published branch which others are using. But if develop is just your own local branch, this is okay.

git checkout develop
git rebase master

History will look like the following. If you want to, after this, you can merge develop branch into master branch and that merge will be a fast forward.

* f1e329c - (HEAD, develop) Develop commit 2
* 066affd - Develop commit 1
* 784442c - (master) Master commit 2
* 03c7803 - Master commit 1
* fcf19a0 - Common commit

Note that for all the three alternatives, you may have to resolve merge conflicts if there are any.

Comments