Use detached branch for deployment
I’m about to set up and automated build environment for a client. I want to push the Git repository to the client’s build server, but without complete Git history.
I’m thinking about an approach with
git checkout --orphan ci, but it’s unclear to me how to work on a daily basis with a branch setup like this.
Maybe something like this (?):
- New commits will be created on the
- A feature is finished after several commits.
cibranch is then rebased/merged (fast-forwarded) on the
cibranch is checked out.
- The recent commits (which are not pushed to any server yet) are squashed to hide unnecessary history from the client.
cibranch gets pushed to the build server.
Is that a valid approach and/or does an easier way exists?
2 Solutions collect form web for “Use detached branch for deployment”
One simple way of managing this could be:
- Work normally on
master(or use any other feature branching model).
Every time you finish a feature and want to push it to the CI system you:
git checkout ci
git merge --squash masterThis will bring all of the changes in
git commitYou will have a pre-populated commit message with all of the squashed commit messages. You can then edit this message to reflect all of the changes in the feature.
git push origin ciTo send your changes to the CI system.
There are many branching models out there, but this should be simple enough and give you what you want.
I hope this helps.
I’d look at something such as http://nvie.com/posts/a-successful-git-branching-model/
As for CI, you’ll probably end up with pretty much the entire branch cloned/checkedout anyway, but unless you’re putting in a bunch of large binaries I wouldn’t worry too much about it.