Copy a git repo without history Copy a git repo without history git git

Copy a git repo without history


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.


Use the following command:

git clone --depth <depth> -b <branch> <repo_url>

Where:

  • depth is the amount of commits you want to include. 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


Deleting the .git folder is probably the easiest path since you don't want/need the history (as Stephan said).

So you can create a new repo from your latest commit:(How to clone seed/kick-start project without the whole history?)

git clone <git_url>

then delete .git, and afterwards run

git init

Or if you want to reuse your current repo:Make the current commit the only (initial) commit in a Git repository?

Follow the above steps then:

git add .git commit -m "Initial commit"

Push to your repo.

git remote add origin <github-uri>git push -u --force origin master