Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a git repo without history

I have a private repository on GitHub that I want to make public. However, some of the initial commits contain information that I don't want to publicize (hard-coded credentials, etc).

What is the easiest route to make the latest commit public (I don't really need or want the previous commits in the public repository) without including some or all of the commit history?

like image 439
Rafe Avatar asked Mar 31 '15 12:03

Rafe


People also ask

How do I copy 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 I just copy a git repository?

Yes you can, but there's no need to copy the full working tree. You can copy just the . git folder without the working tree (i.e. as a "bare" repo) and then checkout the latest working tree on the other machine.

Does cloning a repo keep history?

Go into the repo you want to copy first. Then assuming you have a new repo already set up, use the clone link and that's it. It will copy over all history over to your new repo.


1 Answers

You can limit the depth of the history while cloning:

--depth <depth> Create a shallow clone with a history truncated to the specified  number of revisions. 

Use this if you want limited history, but still some.

like image 178
Gauthier Avatar answered Oct 24 '22 07:10

Gauthier