简体   繁体   中英

How to maintain seperate files in dev and main branches and sub branches github

Question: When merging dev into main , how do I keep them .ebextensions and .elasticbeanstalk commited on their respective branches but never overwriting each other during merges?

Requirement: I wish to checkout new topic branches from dev and merge them back into dev , so these topic branches will need the same .ebextensions and .elasticbeanstalk folders to come with them.

Landscape: Working with Github on Flask project for Elastic beanstalk.

I have two primary branches

  • main
  • dev

I have dev set up for one Elastic beanstalk environment, and main set up in another. This means I have two different versions of the .ebextensions and .elasticbeanstalk folders.

.
├── application.py
├── .ebextensions
├── .ebignore
├── .elasticbeanstalk
├── .gitignore
├── main.py
└── .vscode

I keep messing up the files and having to write them back in locally and push to remote again to fix them.

Having read about a third of git-scm.com's book so I think the solution will involve "onbranch:" includeIf but the example is hard to follow.

Surely I've missed something, it can't be an uncommon requirement.

It seems you already found a possible workaround, but I'd like to propose an alternative solution in which you set Git to never overwrite specific files.

This can be done by creating a .gitattributes file with a pattern matching your files, and then creating a dummy merge strategy.

A more in-depth discussion for this approach can be found here , with some more information here .

I believe that in your case you could do something along the lines of

git config --global merge.ours.driver true
echo ".ebextensions/* merge=ours" >> .gitattributes
echo ".elasticbeanstalk/* merge=ours" >> .gitattributes

Please do note that I'm not sure if passing a hole directory with a wildcard will work, though I imagine it should be possible.

When you do actions in Git, nearly all of them only add data to the Git database was a line I read but didn't apply when trying to resolve this issue.

Thanks to @torek for clarifying.

My summary solution is store all the files

So now my file structure looks like

.
├── application.py
├── .ebextensions-dev
├── .ebextensions-main
├── .ebignore
├── .elasticbeanstalk-dev
├── .elasticbeanstalk-main
├── .gitignore
├── main.py
└── .vscode

When I want to deploy the application to the dev Elastic beanstalk environment:

  1. Remove the -dev from the end of the .ebextensions-dev and .elasticbeanstalk-dev folder names.
files='.elasticbeanstalk .ebextensions'
x='-dev'
for i in $files; do
    mv $i$x $i
done;
  1. Run eb deploy
  2. Add the -dev back onto the end of the .ebextensions and .elasticbeanstalk folder names.
files='.elasticbeanstalk .ebextensions'
x='-dev'
for i in $files; do
    mv $i $i$x
done;

vica-versa for main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM