In my local repository, I have a modified settings file with a different version of the file stored on GitHub. Whenever I pull from GitHub into my local repository, my local copy gets changed.
Is there any way to avoid having my local copy overwritten by git-pull?
While you can do some fancy footwork to fetch branches and check out only specific files, for practical purposes git-pull will merge in all the files that are in the commit manifest. So, you need to change your work-flow.
If there are files you need to store in the repository, but don't want overwriting local changes, the right thing to do is create an example file, and use your .gitignore file to avoid committing the local copy of the file back to the repository. For example:
# Move the repository-managed copy of the example file,
# then add the related local filename to your repository's
# .gitignore file.
git mv .rcfile rcfile.example
echo '.rcfile' >> .gitignore
# Commit the necessary files.
git add .gitignore
git commit -m 'Add example file.'
# Copy the repository-managed example to your local file,
# which will not be overwritten on future pulls.
cp rcfile.example .rcfile
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