Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to realise a deployment branch in Git

Tags:

I'm using git for a PHP project, I think it's really handy. There is one thing that would be great if I get it to work.

I have created a branch, meant for deployment. It has some differences, like different configuration files and documentation.

I can't just ignore them, because then they will stay in both branches, while I would like to keep them different in both branches.

The problem is that when I merge the branches, those files that are meant to be different are merged too.

Is there any convenient way to accomplish such a thing? How is this normally done?

like image 719
Ikke Avatar asked Jan 28 '09 14:01

Ikke


People also ask

How do I know which branch is deployed?

Just go to Overview => latest activity => Search for latest deployed item => Click compare diff on that item => Click on one commit => Check the branch there.

How do I deploy a git branch?

Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch. Simply use a git push origin command on subsequent pushes of the new branch to the remote repo.

What is the name of the branch where the deployment ready code is kept?

The developers in the team constantly commit their work into a single, central branch—which is always in a deployment-ready state. In other words, the main branch for the project should only contain tested and quality work, and should never be broken.


2 Answers

Update Feb. 2021: Git itself is still not a good fit, but GitHub Action environment could help.

2009: I am not sure Git is meant to be used this way.

First a quick Linus advice, always "colorful" and informative ;)

Git very fundamentally tracks project state, not file state. Which means that you very much can NOT try to "merge a file". It is a senseless operation in git, and in fact, any SCM that allows it pretty much is doomed to be a total piece of sh*t (*).

(*) And I'm not saying that just because git doesn't do it. It's much more fundamental than that. Once you start doing per-file branching and merging, you've basically screwed yourself, and you'll never be able to work on the project as a "whole project" any more - you no longer have a well-defined history that actually is the history of the whole project.


There.

That said, you could:

  • manage those config/doc files a separate git sub-projects (note: the use of submodules has been discussed here)
  • or record partial merge (using "ours" strategy for files we don't want to merge), then --amend it.

Other solutions in this thread involve working on a "server-specific" branch on your deployment server

Development        Deployment  #origin/master: x--x               $ git clone                     # master                    x--x                     $ git checkout -b deployment origin/master                     x--x                        \                          -- #deployment                     $ .... #makes changes for config files                           #or other specific deployment files                     x--x                        \                         --d1--d2 # no need to push that branch ever.  #new developments x--x--x--x                     $ git pull --rebase #pull origin/master and                                         #replay current branch on top of it                    x--x--x--x                              \                               --d1'--d2' #SHA1 rewritten in deployment branch                                          #not important since this branch                                           #is not pushed (published)                          
like image 178
VonC Avatar answered Sep 16 '22 23:09

VonC


I do some silly tricks like:

  • Have the app read file config
  • Add config.development and config.production but not config to the repository
  • Have your deploy script not only clone the repository, but also then cp config.production config

Does that make any sense?

It works okay for me.

like image 20
elliot42 Avatar answered Sep 20 '22 23:09

elliot42