I have one remote private Django repo with credentials and such, and I would like to have a public one. When I push my local public as a new branch, I am pushing all my previous private commits as well. How can I push my local public branch to a remote without previous commit history?
-
1After spending a day of search, I finally found what I was looking for: git checkout --orphan public
# create a new branch without parent history – Egor Sep 21 '20 at 03:16
2 Answers
Try following command:
$ git push <remote name> <commit hash>:<remote branch name>
As example it can look like this:
$ git push origin 2dc2b7e123e6b712ef324eqqc81050b9693395a4:master
Remark: This will push
all commits up and including this specified commit! This means if you specify the commit that is at the top of your branch it will push everything, exactly the same as a regular push. You need to reorder your commits first to make sure, the commit you want to push is at the bottom (directly above the remote branch).
How to order commits, you can look at this question.

- 4,222
- 8
- 24
- 34
A simple way to do this would be to copy your repository to a new folder. Delete the .git
folder inside that new folder to remove the previous commit history and then run git init
to create a new repository.
Any commits made in this repository should only be of things that you want to be public so be careful not to commit any private credentials or files.

- 3,927
- 1
- 36
- 52
-
I tried that, but as you are saying, I saw my git got copied over. If delete the .git folder in the new folder does it impact my git history in the original one? – Egor Sep 21 '20 at 02:34