Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Git repo public without revealing past commits

Tags:

git

github

I have a private repo that had a bunch of sensitive data committed. However, I recently cleaned up all of the sensitive data so that it can be public. If I change a private repo on GitHub to become public, are all past commits visible (i.e. could someone see that sensitive data from the past)?

If so, how do I make the repo public without making the past commit history public?

like image 640
Alex Beals Avatar asked Sep 05 '16 19:09

Alex Beals


People also ask

How do I hide previous commits in GitHub?

Hide commit history on Git Branch First, create a new temporary branch and checkout. Now, add all the current files to this temporary branch. Create a new commit. Rename the temporary branch to your old branch name.

How do I make my git repository private to public?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under "Danger Zone", to the right of to "Change repository visibility", click Change visibility. Select a visibility.

How do I move a git repository without history?

i.e. if you just want the latest commit use git clone --depth 1. branch is the name of the remote branch that you want to clone from. i.e. if you want the last 3 commits from master branch use git clone --depth 3 -b master. repo_url is the url of your repository.

Can public see commits on GitHub?

As long as people have access to the git repo, anyone can see any commit and any changes on there.


2 Answers

Go to desired commit:

git checkout <your_commit_hash>

Go down to the initial commit leaving all current changes:

git reset <intial_commit_hash_here> --soft

Then commit with amend option

git commit --amend -m"My new initial commit"

And then you are ready to push to your public repo

git push <your_remote> master

P.S. change history will still be available with git reflog but will not be pushed to remote repo


UPD. To get the id of the first commit use the command from this answer:

git rev-list --max-parents=0 HEAD
like image 128
Teivaz Avatar answered Oct 12 '22 12:10

Teivaz


I'd recommend cloning (or just copying all the non .git files) from the current repo into a new repo and then pushing the new repo out as public.

like image 45
winhowes Avatar answered Oct 12 '22 12:10

winhowes