0

I know this topic has been approach a lot of times but I'm still having trouble to understand the right things I have to do so please excuse me for the repetition.

Here is the situation :

I'm launching a website in a few days so I want to be able to work on code without disturbing the online version. So I'm using git.

I made a repo called MySite on bitbucket.

This repo as two branch.

One master which is from where I push code to my server. This master branch has specific values for the .htaccess, sql access, minified JS etc...

One local which is where I have also specific .htaccess, sql to make it work from my localhost.

I'll focus on .htaccess to be more understandable. My local .htaccess is totally different to my master one.

Which means, I must NEVER merge Local to Master because if local .htaccess gets on prod it will down the server and if prod .htaccess gets on local, i won't be able to access to localhost.

I'll take an example. Let's say i want to work on myScript.js.

I checkout on the Local branch to access the unminified version.

I create a new branch my Script_mods then i checkout on this branch.

I work on myScript.js, i commit the file to branch Script_mods.

(At this step, should i push the Script_mods branch to Bitbucket or not )?

Then i checkout to branch Local and merge with Script_mods. This is to be able to keep tracks of commits and be able to delete Script_mods branch when I'm done with it.

At this point it's all good.

Then I want to also change the prod code so I checkout to Master and merge Script_mods.

Here comes the problem because I have some conflict with the .htaccess file. I don't understand why but i get two kinds of error.

Either the .htaccess is not push but then i get some unmerged errors. Either the .htaccess is modified and I need to rewrite it to get my server working again.

So long story short, I think I'm totally missing something on the workflow i should use but can't see which step...

I'd like to be able to create a branch with only specific files i want to work on then merge this branch to both Local and Master but I'm not sure that's even possible. So i get back to my misunderstanding of regular workflow.

Thanks for your clarifications...

pierreaurelemartin
  • 1,592
  • 1
  • 14
  • 22
  • possible duplicate of [Is it possible to exclude specific commits when doing a git merge?](http://stackoverflow.com/questions/332528/is-it-possible-to-exclude-specific-commits-when-doing-a-git-merge) – Mateusz Sep 02 '14 at 15:33

2 Answers2

0

Exclude those files from version control, because you will not change those often. You will have to maintain those separately. Use gitignore or Git: Ignoring Version-Controlled Files

Ok so answer is here: Is it possible to exclude specific commits when doing a git merge?

Community
  • 1
  • 1
Mateusz
  • 2,287
  • 20
  • 28
  • So there is no way of exclude files from a merge, except totally exclude them from the git system ? – pierreaurelemartin Sep 02 '14 at 14:41
  • If you would ask this way google at start you would get your answer :) I have updated answer with link to right answer. – Mateusz Sep 02 '14 at 15:31
  • I found this post put didn't get it and was already lost into my stuff... But you are totally right... My bad. Anyway, I start from a fresh and clean basis and add files to .gitignore and for now, everything seems working how I'd like. Thanks ! – pierreaurelemartin Sep 02 '14 at 15:39
0

Here is a strategy which should work:

When changing the .htaccess file, then make sure you commit this change alone (i.e. a commit which contains just this file).

When merging such a commit, always do it from local branch (to make sure an error will never break your server). So the workflow would be like this:

  1. Checkout master
  2. Merge everything local -> master branch without the .htaccess commit (i.e. merge all commits before this one).
  3. Switch to local
  4. Merge the single commit from master to local with the merge strategy ours. That basically tells Git: "local is now merged with master" without modifying any files.
  5. Checkout master
  6. Merge the rest

Another approach would be to have to .htaccess files (with different names) and copy the correct one to .htaccess in the server's startup script.

Another good idea is to add a test somewhere in the server's startup scripts which checks for a "local" pattern in .htaccess to make sure you quickly notice when the wrong file is active.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820