4

I have a git repository for a server. That server needs some files, but these files only have to be pushed once. So when someone edits it, then it doesn't have to be pushed to github, but when someone downloads the repository they should get the unedited file.

The server needs these files to run, but for every person are these files different, that's why I don't want it to be pushed again.

How can I do this?

roberrrt-s
  • 7,914
  • 2
  • 46
  • 57
RuuddR
  • 941
  • 4
  • 13
  • 25

3 Answers3

5

If you haven't committed the files yet, i'd say add the filename to your .gitignore file like:

<filename>.<extension>

So in case the file is package.json:

package.json

Wildcards can be made by using the *

*.json

or as AoeAoe remarked: you can add the file later using git add --force to overrule the .gitignore file.

Now if the content of your file is merely 10 rules of config, i'd say: create a mock-up out of it and write it down in your readme.md and instruct your colleagues to create their own, otherwise, you should follow the advice in the update section.

Update: as Edward Thompson stated: .gitignore doesn't apply to uploaded files you'll be forced to use git update-index

To force the file from not updating:

git update-index --assume-unchanged path/to/file

To enable updating again:

git update-index --no-assume-unchanged path/to/file

Community
  • 1
  • 1
roberrrt-s
  • 7,914
  • 2
  • 46
  • 57
1

These files changes should be ignored by git remote repository, since they need a local management. You have to add the path of these files to .gitignore file. If you have already committed and pushed original version of your files, when someone clones the repository, it will receive the original files without any local changes.

How to add gitignore file

How to ignore certain files

Community
  • 1
  • 1
lubilis
  • 3,942
  • 4
  • 31
  • 54
1

It's better practice to remove file from index[1]:

git rm --cached <file>

Purpose of .gitignore is to never track and never add a file to index in the first place.

[1] Making git "forget" about a file that was tracked but is now in .gitignore

agilob
  • 6,082
  • 3
  • 33
  • 49
  • This is not really what I was looking for, thanks, though. Might come in handy later. – RuuddR Sep 09 '16 at 14:51
  • That's not really what he wants though, he wants to have it in but ignore it in commits. Force adding it along with .gitignore inclusion is a way to go here, this is common practice when you want to distribute binaries in your repo but you don't want to bother with them every time people recompile their tree. – Tomas Pruzina Sep 09 '16 at 15:01