GIT Merges and Branches

Git merging and branching is always an issue, and without Git-flow things can get complicated. Here are some simple rules we go by at Wagento.

There will be two scenarios that you will branch from: 1) Branch from Master - You are creating a simple feature that will be used in the site in the near future. *If in doubt always branch from MASTER.

2) Branch from RELEASE - You are creating a branch that is going into a larger release and has dependencies that are not yet in MASTER

NEVER BRANCH FROM ANYTHING ELSE, NEVER BRANCH FROM STAGING or DEV or DEPLOY or any other branch

Scenario #1

git status // to make sure there are no uncommited files git fetch -p // to make sure you have all the current branches from remote git checkout master // make sure you are on master!!

So now you want a new feature. git checkout -b new-feature

Now do your work on this branch, then commit your code to your new feature branch git add . git commit -am 'My rockin update'

Your branch will need to go to the remote repo now git push origin new-feature

So now I don't know where to merge? At Wagento we create a branch for each server, so if the server is dev.domain.com then the branch for that server is dev. If the server is staging.domain.com then the branch is staging.

It is possible that larger jobs could also have a release branch. If a client is adding a new store to a site then the new branch could be called "store-a" This would be a release branch. The case of a new theme is also an example of where we would use a release branch, so something like new-theme.

Your feature branch should get merged in to new-theme and the dev branch.

1) It needs to go to the dev branch so it can be viewed and Q/A'd on the dev.domain.com server. 2) If there is a release then your branch should also get merged to the release branch.

For example, now we need to merge to staging git checkout staging git pull origin staging git merge new-feature git push origin staging

Scenario #2

git status // to make sure there are no uncommitted files git fetch -p // to make sure you have all the current branches from remote git checkout release-branch // make sure you are on the correct branch!! So now you want a new feature. git checkout -b new-feature Now do your work on this branch, then commit your code to your new feature branch git add . git commit -am 'My rockin update'

Your branch will need to go to the remote repo now git push origin new-feature

Now merge back to your release branch git checkout release-branch git pull origin release-branch git merge new-feature git push origin release-branch

← Previous Post Next Post →
Leave a Comment