Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude specific files from 'git pull'

I have a production git repo that I only pull changes from the main repo into; I never change this repo or do commits/pushes from here. I recently accidentally pushed some untracked (at least I thought they were) image files to the main repo from my local dev repo. Now when I try to pull the latest from the main repo, git reports an error regarding overwriting the exiting image file with the file from the main repo. I don't even want this file from the repo (it's located in a ,gitignored directory on the production repo)

How can I a) get rid of these unwanted image files in my main repo, or b) exclude these files from my git pull?

like image 713
Chris Barnhill Avatar asked Aug 05 '13 20:08

Chris Barnhill


People also ask

How do I exclude certain files from a pull request?

To exclude certain files from appearing in pull requests: In the repository containing the pull request, click Repository settings > Excluded files in the Pull Requests section. In the Patterns field, enter patterns to exclude from pull request diff views. Click Save.

How do I exclude a file in git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Can I pull specific file from git?

git checkout origin/master -- path/to/file // git checkout / -- path/to/file will checkout the particular file from the downloaded changes (origin/master). That's it!

How do you exclude or ignore some files from git commit?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.


2 Answers

This allowed me to tell git to ignore a specific file, even though it was already part of a project. All changes I make to it will be ignored:

git update-index --assume-unchanged Localization/el-GR.js 

Source: http://codethug.com/2013/09/20/4-ways-to-ignore-files-with-git/

like image 110
Eduardo Cuomo Avatar answered Sep 29 '22 05:09

Eduardo Cuomo


git pull is equivalent (almost) to git fetch && git merge. You just have to invoke fetch and than merge only specific files - tutorial.

like image 41
kwarunek Avatar answered Sep 29 '22 06:09

kwarunek