Let's say we have three files in a GIT repo:
.gitignore (file content: config.py)
config.py
main.py
When we clone this repo with git clone https://github.com/example/test
, we now have these 3 files in a folder, which is ok.
Now let's do local modifications to config.py
.
Then a few days later, we want to pull the latest modifications with git pull
. Problem: it also wants to merge config.py
:
error: Your local changes to the following files would be overwritten by merge: config.py
which we don't want.
TL;DR, this is the desired workflow:
git clone ...
, config.py
should be clonedgit pull ...
, config.py
shouldn't be pulled/merged/overwritten if it has been locally modifiedWhat's the standard way to handle this situation?
The standard way is to put config.py.template
(or whatever you want to call it) in the repo, with the formatting and default values for config.py
. People who want to use the repo will need to clone the repo, copy that file to config.py
, and make their local changes.
A slightly different option is to use CI/CD to reject any commit that modifies config.py
. This is not as useful, though, because you won't be able to update config.py
to include new options or remove old ones.
Note that .gitignore
is not retroactive - if you've already added config.py
then you'll need to run git rm --cached config.py
to remove it from the index.