git - Is it possible to exclude file from `git push`, but keep them in the local repository?
You can go ahead and actually track these files (sans the sensitive info), but then use:
git update-index --assume-unchanged <file>
on each file. Then you can go ahead and add the sensitive info to each file, but Git will not see the file as changed, and not try to commit (and thus push) that sensitive info.
To get Git to update the info again, you'd use:
git update-index --no-assume-unchanged <file>
This is not possible. If you have committed a file, then it will be pushed. The push action only acts on commits, not on a file basis.
But you could use a submodule for your sensitive data and keep this submodule on your local machine, while you push the regular git repository to the remote machine.
The way I eventually got around the issue is the following: Put the sensitive information in a sub directory with its own git repository and symlink the file(s) back to the old location.
E.g. in your home folder (~
) lives the file .creds
which you do not want in the public repository. Move this file in a sub folder called, say protected
and create a symlink from ~
to protected/.creds.
Of course, do not include this folder in your ~
repository , but create a new repository in the folder protected
just to keep track of .creds
. If you do not push this repository publicly at all, you are set.
I know this solution is kind of a cop out: My questions states that the file resides in the same directory, but the symlinking works for me.