Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git to maintain a slightly different copy of production source code?

I have a Ruby on Rails application, which sends out emails.

In production, I want to use some X SMTP server, but in development I want to use some other SMTP server (thus my configuration file for the SMTP settings is different in the development and production environments)

So I need to maintain 2 configuration files (one file each for the development/production environments' SMTP settings).

As of now, I keep settings for Y STMP in a file on my development machine. I clone the production code from the github repo, modify the working copy with settings for Y SMTP and proceed. Then when I have to push changes to github, I reverse the process. It works, but I'm thinking there should be a better way?

What is the "git way" to handle this sort of "small differences" between development and production code bases?


UPDATE

Per @Mike Axiak, is this the flow that you mean: (presume for simplicity that I'm not using ln, but using the copy method)

Set up source code so that there are 2 settings files on local machine:

  • smtp.settings.prod
  • smtp.settings.dev

Both are added to .gitignore

To work on local copy:

  • Pull code from github
  • Copy smtp.settings.dev to smtp.settings
  • Use.

To push changes to server:

  • Just before push, copy file smtp.settings.prod to smtp.settings
  • Push

If this is what you meant, is there some way to automate the copying process via git?

like image 549
Zabba Avatar asked May 03 '11 19:05

Zabba


People also ask

How do I copy code from one Git repository to another?

Navigate to the repository you just cloned. Pull in the repository's Git Large File Storage objects. Mirror-push to the new repository. Push the repository's Git Large File Storage objects to your mirror.

Is git a source code management tool?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny footprint with lightning fast performance.


1 Answers

Rails already support this kind of thing using the files the configuration/environments directory. Just add your settings in the appropriate file.

like image 166
Andy Waite Avatar answered Oct 21 '22 15:10

Andy Waite