I usually maintain a release branch to upload my code to the stage environment or production. Its very common to have some sort of config files which are related to the targeted environment. For example: database connection files, api URLs etc. And I believe that everyone uses different DB and APIs for dev and prod. Yes we use! 🙂
Now the problem begins when we merge our master branch with release and all of our config files gets overwritten. What the F**K. Its again rework on our end to fix those files to make our code work on that particular environment.
There are some workarounds to get rid of this sci-fi thing in a very simple way.
Lets assume we have a repository called captain-cool. Currently we are in master branch and we have a
config.xml having my database connection specific details.
Now its time to move our captain-cool project to production. Lets create a new branch called
git branch release1.0
above command will create a branch on local with exact copy of our
master branch which is ready to get pushed on our git server.
We have to switch to our very new branch. So let’s do then.
git checkout release1.0
Now lets go to our
config.xml file and make appropriate changes as per the environment we are planning to use.
Now we are in
release1.0 branch and can make our push move.
git add -all git commit -m "updating config for stage" git push origin release1.0
enter your credentials and our
release1.0 branch with updated
config.xml file is on the git server. Congratulations!
Now the action begins when we have added some new cool features and wanted to push those features to
release1.0 branch to make them live.
Let’s switch back to
master branch and do some modifications.
git checkout master
Doing some changes ……….@#@########&*(&&
Now lets push our new features to
git add --all git commit -m "adding some cool features" git push origin master
Now, Its time for our heroic move to merge our new cool features from
Let’s do then.
- switch to
git checkout release1.0
- run merge command with option
git merge --no-commit master
--no-commitoption don’t commit your merged changes to the repository. we did make use of this option just because we want our
config.xmlfile to keep un-touched. Remember right?
- Now we have to revert our
config.xmlfile as per the last commit to our
release1.0branch as our last commit had the version that we want to keep.
git checkout HEAD -- some/path/config.xml
We have our old
config.xmlfile with us
- It’s time to commit our merge.
git commit -m "merged cool features from master"
- And in final step, let’s push our cool features to our
git push origin release1.0
Here we have successfully merged changes from
release1.0 keeping our
If you guys have more than one file to ignore then I afraid you have to loop step 3.
Guys let me know if you came across a better solution to do this as I found this solution little long and time consuming.
Sometime I want to create a command line utility to merge all those above steps. Let me know if anybody did that.