Start a git repository using files from an external repository

I would like to start a new git repository but using the files of an external 3rd party respoitory as my starting point.

I have an empty repository sitting on branch master with no files in it. I now want to add files as my first commit, but the should be copied from another git repository.

  • How do I refresh branches (local/remote) in Visual Studio when using Git?
  • Keeping an alt branch up to date with common
  • Cloning a tree in git
  • Git flow: Best practice for dealing with minor releases
  • Why does git-rebase give me merge conflicts when all I'm doing is squashing commits?
  • What is the difference between running “git mv” versus just “mv”
  • Is there a git way to do this, or should the repository be checkout out and the files copied in to my repository.

  • Upload a project to github C# Visual Studio
  • git push still issues RPC error after changing postBuffer
  • Hosting a Git repository on an AWS Windows Server
  • Move .git repo to parent directory
  • How to make Local branches configured for 'git pull':
  • Git: Merge in only one commit
  • 2 Solutions collect form web for “Start a git repository using files from an external repository”

    If you would like to preserve the history from the remote repository, you can do this:

    # Initialize your local repository
    git init
    # Add the source-repo where you want to pull the files from
    git remote add source-repo <URL of Source repo>
    # Make git fetch the history for the source-repo
    git fetch source-repo
    
    # Merge from BRANCH_NAME of source-repo into
    # the current branch (which should be called master by default)
    git merge source-repo/BRANCH_NAME
    

    If you just want a single commit to add (i.e. merge) the files, instead of multiple commits, you can make use of squash-merge. As of now (March 2013) git does not support squash merges on an empty repo. So you would need to have at least one commit prior to doing such a squash merge.

    So you could do something like this:

    # Initialize your local repository
    git init
    # Add the source-repo where you want to pull the files from
    git remote add source-repo <URL of Source repo>
    # Make git fetch the history for the source-repo
    git fetch source-repo
    
    # Create a dummyfile and commit the change
    touch dummyfile
    git add dummyfile
    git commit -m "Dummy file change."
    
    # Create a squash merge from BRANCH_NAME of source-repo into
    # the current branch (which should be called master by default)
    git merge --squash source-repo/BRANCH_NAME
    

    No need to check out and copy. You just need to let git know about the remote repository, and then you can merge from it, like this:

    git remote add the-remote-repository <url of remote repo>
    git remote update
    git merge the-remote-repository/master   # or whatever branch you want to pull in
    
    Git Baby is a git and github fan, let's start git clone.