How to do branching approach for multiple sites?

2020-07-25 01:48发布

问题:

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.

回答1:

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.