2

I'm new to git and would want to know if this branching approach would be okay for what we intended to do.

We'll have three sites

  • prod.websitename.com - live site
  • sandbox.websitename.com - testing site that can be used by our clients
  • dev.websitename.com - internal site for developing and testing hotfix/features before pushing to live site

What we intend to do is to have a single centralized repository that would serve all three sites. The repository will have three branches: master, sandbox, and development

and then we'll just checkout the branch to change files and pull/push the changes for each site.

For changes, development will be pushed to both master and sandbox branch. Sandbox will never be pushed to master.

Is this okay? Any advice is highly appreciated.

Thank you so much.

Woppi
  • 4,468
  • 8
  • 40
  • 74

1 Answers1

0

It can work, provided your main single repo is a bare repo to which you can push.

From there, a post-receive hook can trigger the relevant checkout, depending on the branch which has been pushed (see "Writing a git post-receive hook to deal with a specific branch")

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    if [ "master" == "$branch" ]; then
        # Do something
    fi
    if [ "sandbox" == "$branch" ]; then
        # Do something
    fi
    if [ "development" == "$branch" ]; then
        # Do something
    fi
done

For changes, development will be pushed to both master and sandbox branch. Sandbox will never be pushed to master.

That is not the best practice: you should merge what you need from dev to the master and sandbox local branches, and then push those branches to the unique remote repo.
Regularly rebasing dev on top of master is also a good idea.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • I really appreciate your advice. BTW, Yes, it's a bare repo. I'm the only committer... and saw your link provided on another GIT stackoverflow post "A Rebase Workflow for GIT". I think i'll try to follow that rebasing idea... "take all the changes that were committed in dev and replay them in both master and sandbox" then push each branch to unique repo branches. That's how I understand your explanation... as for the hook... it's just overwhelming for me now as a total beginner on this stuff and really can't understand its value. Thanks Von! – Woppi Apr 18 '13 at 01:56
  • @Woppi the hook is key to automate the checkout of the bare repo on the right places, as in http://stackoverflow.com/a/15930178/6309 – VonC Apr 18 '13 at 05:10