Home > Back-end >  Automatically adding local changes on top of a git repo that are never to be committed
Automatically adding local changes on top of a git repo that are never to be committed

Time:01-06

Sometimes, in projects, I have to perform local changes for development. These changes must never ever be committed - they are strictly meant for debugging and development only. One example of this is a method that performs various checks to validate an operation - I might want to turn those checks off and always have the operation validated for development. If i am the author of that project, I can try to add something akin to C/C #ifdef lines to turn such code on/off, but not all languages allow for that (and the method's code may be such that something like decorators and/or injection does not work well for this purpose). Furthermore, if I am not the owner but instead a contributor, then the project owner may not want #ifdef lines and similar to be present at all.

Currently, in such cases, I use a local branch that contains these custom changes. I rebase that branch every time I incorporate upstream changes. However, I wonder if there is a smarter way to do this. Perhaps something like a special stash that is auto-applied after a git pull? Right now, with the custom branch approach, there is a possibility that the commits that contain these development hacks can accidentally end up being pushed. I know there are a lot of advanced tricks that you can do with git, so perhaps there is something for this case as well?

CodePudding user response:

I usually solve this with following approach:

I will add filename .local_development or .debug or something similar to my .gitignore and then I create this file in my project directory. My project is then available to check if this file is present and adjust the process according my debug needs.

If you can not / don't want to do it this way, debug branch with adjustments being rebased on top of upstream changes seems to be the right approach.

  •  Tags:  
  • git
  • Related