Chris Barnhill
Chris Barnhill

Reputation: 641

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?

Upvotes: 45

Views: 66440

Answers (3)

Matthew
Matthew

Reputation: 21

I stumbled here while looking for a way to update my local branch with remote/branch but not a particular directory from remote/branch.

The solution for such was using git sparse-checkout feature, where you can define paths to exclude and/or keep on your work tree, effectively working with a subset from all files.

If that is what you need, then you may resort to the official documentation or follow a small (useful) tutorial

Upvotes: 1

Eduardo Cuomo
Eduardo Cuomo

Reputation: 19006

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

Notes

  • It's ignored by git status, but not by git pull. You can solve it with something like git remote update && git checkout origin/main -- Localization/el-GR.js in order to retrieve the updated version.

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

Upvotes: 31

kwarunek
kwarunek

Reputation: 12597

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

Upvotes: 9

Related Questions