How to remove private keys on push to a public git repo?

Brett Best September 29, 2014

I would like to push my repo to a public host but it contains private keys.

How can I remove these before pushing? Can SourceTree do this automatically? I.e. find and replace text on push?

1 answer

1 accepted

0 votes
Answer accepted
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2014

I don't think Git/Hg or SourceTree provide a way to do this. The entire point of pushing and pulling is to keep repositories synchronized.

At this point, even deleting the private keys from your repo will be insufficient If you're pushing the entire repo, others will be able to look through the repository history to find them.

There is probably a complex Git/Hg command that can iterate through your history and delete all instances of a file, but you'd get more help with that in a larger forum, like StackOverflow or a Git/Hg mailing list.

Brett Best September 30, 2014

Okay what about on committing or do you have another way of handling private keys with a public repo?

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 30, 2014

I think most people would recommend to keep private keys outside the repo. You might consider a separate, private repo where you can store keys and any other non-public documentation.

Brett Best October 1, 2014

Thanks Seth!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events