Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing certain files from being pulled in git

Tags:

git

I have some files that I want to be ignored via git pull on a remote machine. I still want it to be a working copy, for updating only the changes. On my local machine I don't want those files to be ignored.

I tried adding the files in .gitignore on the remote machine, but I guess it's only for commits.

How to accomplish this?

like image 985
owzim Avatar asked Oct 04 '12 01:10

owzim


People also ask

How do I exclude files from a git repository?

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.

How do you exclude a file from a 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.

What files should not be stored in git?

You shouldn't store credentials like usernames, passwords, API keys and API secrets. If someone else steals your credentials, they can do nasty things with it.

Does Gitignore affect pull?

gitignore file on the clients that has "sample. db" listed in it, but this does not change the behavior of git pull.


1 Answers

You cannot - the point of git is you get a full copy of the repository - you are implementing the "I have a hammer so everything is a nail principle" and trying to make it do something is was never designed to do - I suggest you switch tools if the is a break all requirement.

If you do not want the file in the repo - do not add it.

If you want to control access to certain files - move them to a separate repo and restrict access.

like image 128
Adrian Cornish Avatar answered Oct 14 '22 03:10

Adrian Cornish