Cloning a Git repo into a new repo – without commit history

So I’m trying to get my head around Git, and have the need (why I have this need I won’t go into) to be able to take the files from one repo, via command line, and put them into a brand new repository WITHOUT taking all of the previous commit history with it.

What I’m trying to do at the moment is git init to create a new repository, and then grab the files from my existing repo, either using clone or subtree (I’ve not got my head fully around this yet so may be barking up the wrong tree), and then add, commit, and then push these to my new repository.

  • Android Studio: git repository with multiples modules
  • cloning a private bitbucket repository given access to me
  • How to use special SSH key for BitBucket and GitHub to push/pull?
  • “Bad configuration option” on linux terminal, during bitbucket ssh connection.
  • Mirroring a HG project from Bitbucket to Github
  • Bitbucket git credentials if signed up with Google
  • git init
    --- get the files from stock repo ---
    git add .
    git commit -m 'Initial commit'
    git remote add origin <url of my new repo>
    git push -u origin master
    

    My repositories are all on Bitbucket, if that makes a difference,

  • git push “ The remote end hung up unexpectedly ”
  • Ignore modifications after git add -f
  • GWT Source Code Repo - GIT and SVN - which is the one to track for changes?
  • Removing all deleted files from git repo history w search command
  • How can I resume a git history rewrite?
  • What does git pull . do?
  • 3 Solutions collect form web for “Cloning a Git repo into a new repo – without commit history”

    You can clone the old repository like:

    git clone git@bitbucket.org:username/repository.git
    

    and then you delete the git directory:

    rm -R .git/
    

    Now you create the new repository:

    git init
    

    If you have those files from stock repo cloned somewhere, you can do a:

    cd yourNewRepo
    git --work-tree=/path/to/stock/repo add .
    git commit -m 'Initial commit'
    

    That means: you are considering the files from /path/to/stock/repo as your working tree for your new repo (just for the git add step)

    Once the index of your new repo has recorded those files, you can forget about the stock repo, and commit those new files (without any prior history) in your new repo.

    If you’ve already got the TMI repo cloned you can reset your clone’s master to have only that one’s tip commit for history with

    git branch -f master `git commit-tree -m "My new initial commit" origin/master^{tree}`
    

    and then do as usual, fix up the remotes and push histories around as as you like.

    (edit: if you’ve got master checked out git branch won’t want to rewrite the ref, but you’re not touching the content at all, so you can bypass all the porcelain’s handholding and just do it

    git update-ref -m "Truncating history" refs/heads/master \
            `git commit-tree -m "My new initial commit" origin/master^{tree}`
    

    )

    Git Baby is a git and github fan, let's start git clone.