1

I have a private online repository that I have been using for a little while. I would like to make it public now, however it holds confidential information. As I'm still relatively new to Git / Github, I'm not sure how to go about this as the way I understand is if I delete any of these files in the repository they will also be deleted locally on my next pull.

My current idea is to create a new branch and only push the files I actually want stored on the repository. Then make this new branch my new 'default' master branch and delete the old master branch.

Would this work? Are there any better alternatives?

Glanyx
  • 409
  • 1
  • 4
  • 10
  • 1
    `Would this work?` ... what you are alone suggesting _won't_ work, because those confidential files will forever be a part of your history, even if you delete them from a new branch. If you really want to purge the files, you might need to use something like filter-branch, and remove all traces of these files from your history. – Tim Biegeleisen Sep 27 '18 at 13:31
  • Possible duplicate of [Remove sensitive files and their commits from Git history](https://stackoverflow.com/questions/872565/remove-sensitive-files-and-their-commits-from-git-history) – phd Sep 27 '18 at 15:59
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+sensitive+file+history – phd Sep 27 '18 at 15:59

2 Answers2

1

Take a look at the git filter-branch command. This one rewrites your repository's history, which changes the SHAs for existing commits that you alter and any dependent commits. Changed commit SHAs may affect open pull requests in your repository, so it is recommended to merge or close all open pull requests before removing files from your repository.

See https://help.github.com/articles/removing-sensitive-data-from-a-repository/ for more information.

Nevertheless, it is not clear from your post, are you planning to save the confidential info from your old repo or not. If positive, you'd better make a copy of your private repo, remove all confidential information from it and push that all as a brand new public repo to GitHub.

Arfeo
  • 870
  • 7
  • 20
  • Ah, I guess I wasn't too clear on that, apologies. The confidential information is access tokens, etc. So I still need this going forward, I simply wish to exclude it from any future commits. So if I decide to create a completely new repo so that I can exclude these files, I won't have to use the git filter-branch command, correct? – Glanyx Sep 27 '18 at 15:18
  • @Glanyx correct, you only have to remove all sensitive data from a new repo before pushing it to GitHub. – Arfeo Sep 27 '18 at 15:27
0

Have a look at Git BFG (see reference below) it allows you to remove files from a repo (creating a new repo that you can push). The link shows a number of use cases.

https://rtyley.github.io/bfg-repo-cleaner/

Rich Duncan
  • 1,845
  • 1
  • 12
  • 13