rEDSAMK
rEDSAMK

Reputation: 109

Maintain some changes on git merge

I'm a bit confused about a git mechanics.

My work has 3 branches master devel and public. I use master for deploy my Node.js app into OpenShift (or heroku); devel is where i develope my feature and i use public for push my open source code on GitHub.

Everytime i have to deploy my app on OpenShift i just merge from devel to masterand then push. Same for git, i marge from devel to public

Problem is: example. i have a file, index.html in witch there is a snippet of code for private Google analytics. Or ex. i need some files for deployment in master but not in public

Question is: how can i keep this snippet of code and files in master but not in public?

I thought about 2 (non working) strategies:

1) Snippet\files are not present in devel but are present in master --> i merge devel in master --> snippet\files are deleted from master

In this manner i'm fine with public (because will not include the private snippet\files) but i'm not fine with master

2) Snippet\files are present in devel -> if i merge devel to master i'm fine with my deploy on OpenShift because the snippet\files are included.

but merging devel in public --> now public has my private files.

Gitignore file can't help me, because are shared between branches and if i ignore my private files they will be ignored in my master deploy too. And even so this will not resolve the snippets problem.

TL.TR. How can i merge 2 branches keeping some file\part of codes unmerged? Possibly in a simple way, because i have to do this for a lot of file.

Or, how can i change my branch strategies for achieve this?

Upvotes: 1

Views: 92

Answers (2)

Vinay
Vinay

Reputation: 546

You can change your branch strategy to achieve this. I am assuming that all of you public code should also be present in your master branch.

You can have 4 branches (instead of 3) eg. master, dev-master, public and devel

  • You should do most of the development(except private files) on devel branch and merge it to dev-master and public whenever you want to. Since it doesn't have any private file, it would not be merged to public branch.
  • When you want to write your private code, just switch you branch from devel to dev-master before start writing your private code and then test your feature here. Once everything is correct, merge dev-master to mater branch.

With this strategy, you can also test your code with/without private files which would be helpful in maintaining the code base.

I am not sure if this is the best strategy. I hope this helps you !!!

Upvotes: 1

zwik
zwik

Reputation: 89

I found a website that knows how to do this. You can use excludesfile for different branches.

Here's how to do it:

$ git branch public_viewing
$ cd .git
$ touch info/exclude_from_public_viewing
$ echo "path/to/secret/file" > info/exclude_from_public_viewing

Then edit the .git/config file and add:

[core]
excludefile = +info/exclude

[branch "public_viewing"]
excludefile = +info/exclude_from_public_viewing

Using this approach everything all the public files are in info/exclude_from_public_viewing and the personal in info/exclude.

The website can be found here: http://cogniton-mind.tumblr.com/post/1423976659/howto-gitignore-for-different-branches

Upvotes: 1

Related Questions