I'm working on a (Django) website with two branches: master
and dev
.
master
is the production version and no work should be done here directly. All the changes should come from merging dev
branch, once it is considered to be stable.
dev
, as you may guess, is the development branch and all the changes are made here (and subbranches).
In the server I have two websites working, the production one (uses master
branch) and another private for development, with dev
subdomain that uses dev
branch.
The problem is that all the configuration files, static files (images, etc.) are inside the control version to be able to easily push them to the server. But, if these kind of files (static, config...) are modified in dev
to just debug in the server and then I need to merge with master... How can I set some files and dirs to be ignored when merging dev into master?
I've been searching and I've found some related questions, but they tell you to use .gitattributes
with merge=ours
. However, this approach has a big caveat: it only applies the strategy if the file is modified in the two branches, but this isn't my case.
Any tips on how should I go on?
The simplest way, if you have unmerged paths, use git merge --abort to abort the merge. This way your code will look the same as it was before trying to merge with some other branch...
Let's say I'm on branch staging want to merge dev and ignore changes in /build folder: git checkout staging # go to staging branch git checkout dev .
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
git checkout master git merge --no-log --no-ff --no-commit dev git checkout master <files-you-don't-want-to-merge> git add <files-you-don't-want-to-merge> git commit -a ~~~ Test / Build ~~~ git push origin master
To be honest, git sounds like the wrong place to be solving this problem.
Django offers facilities for having separate settings/configuration for production and development environments. I suggest you take a look at this post: Django: How to manage development and production settings?
If you follow the advice in the post above, you can muck with the configuration, etc. for your dev environment and then merging to master will be harmless as production will have its own configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With