Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merging development branch with master for production versions

Tags:

git

git-merge

I'm using Git for code versioning.

I have a development branch on which i'm doing all the dirty development.

Every time I publish a production version to the world, I want to put it under my master branch.

The problem is that whenever I merge development and master, master receive all development history.

I want to keep everything clean so the branches will look like this:

development

"init commit"

"developing"

"Version 1.0"

"bug fixing"

"bug fixing"

"Version 1.1"

master

"Version 1.0"

"Version 1.1"

Is it possible? and if so, how ?

UPDATE I tried to use Gauthier answer but it doesn't worked as I wanted.

The steps I took was as followed: 1. created an init commit in master 2. switched to development. 3. added few commits to development. 4. checkout master 5. git merge development --no-ff

The merge was successful but when i'm looking on high level at my repository, I see that in my master branch I have all the history of the development branch, while I wanted to have only init-----version 1.0.

This is screen shots of how it looks:

development branch: enter image description here

master branch: enter image description here

like image 405
Asaf Nevo Avatar asked Apr 30 '15 12:04

Asaf Nevo


People also ask

How do I merge a branch with develop?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

Should you merge master back into develop?

Once you merge develop to master then both are already in sync with each other so there is no need to merge again master into develop.


1 Answers

Do you know about --no-ff?

You currently have:

o init commit
|
o developing
| 
o Version 1.0
|
o bug fixing
|
o bug fixing
|
o Version 1.1
|
o Version 1.0
|
o Version 1.1  - development - master

(time going downwards as in your example, instead of what git log and gitk do)

My guess is that you are unhappy with master because everything gets directly there, at the same level.

If you would be happy with:

o init commit
|\
| o developing
|/ 
o Merge branch 'development' - Version 1.0
|\
| o bug fixing
| |
| o bug fixing
|/
o Merge branch 'development' - Version 1.1 - development - master

then when you want to release what you have in development, merge to master with --no-ff, and tag:

$ git checkout master
$ git merge development --no-ff
$ git tag "v1.0"

Note that you should consider working in branches named after the feature you are working on, rather than everything in development. This would lead to better merge messages, such as "Merge branch 'killer_feature'". Maybe that's what you have in development already, in that case, sorry.

like image 79
Gauthier Avatar answered Nov 15 '22 04:11

Gauthier