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

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

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.

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

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.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

570 views 1 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you