Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use merge or rebase to maintain a deployment branch

I host with AWS which means I cant use environment variables to control my production and staging deployments. I am therefore forced to use separate branches for deployment, and am wondering if there is a best practice approach towards their maintenance?

If I merge changes into my production branch, the commit that contains my production settings will get lost in the branches history, making it more difficult to tweak those settings.

However I have read that you shouldn't use rebase in this situation as it will make it more difficult to roll back changes.

like image 621
pingu Avatar asked Oct 30 '14 15:10

pingu


People also ask

When to use rebase or merge?

All the commits on a feature branch are combined into a single commit on the master branch. All commits are rebased, and the same number of commits are added to the master branch. Merge is best used when the target branch is supposed to be shared. Rebase is best used when the target branch is private.

Should I use git merge or git rebase?

Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .

Why is rebase better than merge?

Git rebase compresses all the changes into a single “patch.” Then it integrates the patch onto the target branch. Unlike merging, rebasing flattens history. It transfers the completed work from one branch to another. In the process, unwanted history is eliminated.

When should you merge branches?

Once you've completed work on your branch, it is time to merge it into the main branch. Merging takes your branch changes and implements them into the main branch.


2 Answers

I also faced many challenges to implement git in my latest project. After too much googling I found this blog and it is really a nice way of maintaining git branch model.

A successful Git branching model enter image description here The central repo holds two main branches with an infinite lifetime:

  • master
  • develop

The master branch at origin should be familiar to every Git user. Parallel to the master branch, another branch exists called develop.

We consider origin/master to be the main branch where the source code of HEAD always reflects a production-ready state.

We consider origin/develop to be the main branch where the source code of HEAD always reflects a state with the latest delivered development changes for the next release. Some would call this the “integration branch”. This is where any automatic nightly builds are built from.

Supporting branches

The different types of branches we may use are:

  • Feature branches
  • Release branches
  • Hotfix branches

Feature branches : Feature branches (or sometimes called topic branches) are used to develop new features for the upcoming or a distant future release.

May branch off from: develop

Must merge back into: develop

Branch naming convention: anything except master, develop, release-, or hotfix-

Release branches : Release branches support preparation of a new production release. They allow for last-minute dotting of i’s and crossing t’s.

May branch off from: develop

Must merge back into: develop and master

Branch naming convention: release-*

Hotfix branches : Hotfix branches are very much like release branches in that they are also meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version.

May branch off from: master

Must merge back into: develop and master

Branch naming convention: hotfix-*

You can find more details about this Git branching model from the blog. The commands used for the branching model also listed in the blog. Check the blog for more details. I successfully implemented the branching model in my project with some changes from the model mentioned in the blog. Git is a powerful and flexible tool,and this is just one way of using Git.

like image 98
Damodaran Avatar answered Sep 19 '22 22:09

Damodaran


There are a few links below that share some opinions on methodologies and the reasoning behind why you should choose rebase or merge.

  • Merge is ideal for committing code to a shared branch among a team. Since Rebase rewrites the history of the commits, context of related commits (like feature branching) is lost since the commits become linear based on the timestamps.
  • Rebase can be ideal for pulling code into your working branch before committing back to a shared branch. The linear results and historical changing can lead to more successful merging of the commits.

See:

  • http://blogs.atlassian.com/2013/10/git-team-workflows-merge-or-rebase/
  • http://www.derekgourlay.com/archives/428
like image 36
Jason W Avatar answered Sep 21 '22 22:09

Jason W