In my home directory I have files in a local git repository, because I want track them all under version control.
Most of these files I want to push to a remote repository, but a few I want to keep in my local repository only (they contain mildly sensitive information).
How can I achieve this with git? Can I configure a ".gitignore-for-push
" file? I cannot use the local .gitignore
file, because it would exclude these files completely from being tracked.
ps: I am aware of question Is there an exclude file-equivalent..., but the answer goes down the .gitignore
path which I cannot use. The other question Exclude specific files when pushing... answers only a specific case for git+heroku, not git alone.
Execute the following command: git rm --cached path/to/file . Git will list the files it has deleted. The --cached flag should be used if you want to keep the local copy but remove it from the repository.
Open the . git/info/exclude file in a text editor and add the folder to ignore. This file remains private to you.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With