Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid merging a specific file with git-pull?

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?

like image 795
Sreedhar Prabhu Avatar asked Nov 13 '22 14:11

Sreedhar Prabhu


1 Answers

You Can't Pull Partial Commits

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.

Proper Work-Flow Using Example Files

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
like image 166
Todd A. Jacobs Avatar answered Nov 15 '22 05:11

Todd A. Jacobs