I got a git repository where I got several files. (Actually it's my Advent of Code repository)
In this repository is a file which I want to keep in the GitHub remote but I don't want git to update it, even if this file changes locally. Also I want this behavior automatically on every machine where I clone this repository to.
So basically these steps:
- Create file and add initial content (v1)
- Commit and push file to remote branch
- Do something that lets git ignore all changes to this file on every machine
- Change the file content (v2)
Now I got the file in the remote (v1) and locally (v2) but I don't want to see anything about this file when I run git status
. Also if I clone this repository (with file v1) to another machine and make changes to the file (now v3), I don't want to see anything in git status
about this file on the other machine.
To provide an example: I want to add the file which will contain my session cookie to GitHub. Obviously I don't want to push my session cookie to GitHub, just the a placeholder or something. But when I run the program, it must contain the right session cookie, so I have to update the file with the actual cookie. Now I don't want git to update this file to GitHub. And when I clone this repository to another machine, I want it to contain the placeholder like in the remote which I can then update manually. Also git should not want to update the file from this machine either.
First I tried adding it to .gitignore and running git rm --cached myfile
but then git wants to delete this file from the remote as well.
I tried with git update-index --assume-unchanged myfile
. Which technically does what I want, just not on all other machines because it only affects my local git repository.
Is there even a way I can accomplish what has to be done in step 3?