Git clone repository into root of other repository?

If I have an empty repository git init and I want to pull in another repository to be used only for pulling in updates how can I do this if I want the files to be in the root directory?


  • Stop git flow from creating a tag automatically
  • Switch between user identities in one Git on one computer
  • Git: handling an appcache?
  • Git man page seems incorrect
  • What happened if I didn't add a dot at the end of `git checkout `?
  • git: Show message of last commit in commit template
  • lets say:

    cd ~/repositories
    mkdir newrepo
    cd newrepo
    git init
    echo "testfile" >
    git add .
    git remote add <whatever>
    git push -u origin master
    #ok so that part works fine
    #now we have our repository at <my_other_repository> that looks like
    #so now I want to run something like:
    git clone <my_other_repository>
    #and end up with:
    #if I then run
    echo "edited testfile" >
    git status
    #I want to be told that
    #untracked changes
    #newfile: a_root_file.ext
    #newfile: directory/another_file.ext
    git commit -a -m "Some files from another repository"
    git push
    #should push everything up to the <whatever> repository
    #then I want to be able to run
    git pull <my_other_repository_name>
    # and have it pull in any upstream changes

    Is this something it is possible to setup?

    I imagine I could work around it slightly by having a “wrapper directory”

    cd ~/repositories
    mkdir newrepo
    cd newrepo
    git init
    git remote add <whatever>
    mkdir wrapper #this will now be the root of my project
    cd wrapper
    echo "testfile" >
    cd ../
    git add .
    git push -u origin master

    I should then be able to run git clone <my_other_repository> without issue but this will only work if I only want to merge in one repository, and I am wanting to merge in several repositories and I also wonder what would be tracking the changes since there are now two repositories watching the same files, would both track them? or would <whatever> say “hey these are under this repository, so we won’t track it!”?

  • Find added files in index before an initial commit is made
  • What is the default behaviour of “Resolve using theirs” in git
  • Git - error: RPC failed; result=22, HTTP code = 401 fatal: The remote end hung up unexpectedly
  • Git (Sourcetree) branching and merging - not sure what I did
  • Pygit2: Why does merge leave branch in an unclean state?
  • Customize gitk for each repository
  • 2 Solutions collect form web for “Git clone repository into root of other repository?”

    I’m not quite sure exactly what you’re asking for here, but you should be aware that you can have more than one remote. For example, you could:

    git remote add another <my_other_repository>

    Then, you can pull in updates using git fetch another. You can then merge in updates using:

    git merge another/master

    to merge updates from your other repository into your local repository.

    I think the best way to accomplish this would be to have two repositories — but have one of them be a fork of the other and then pull commits from one into the other.

    Having two different repositories where one is a fork of the other ensures that individual commits are easily tracked between the two. If you have two different repositories, then you may have to pull changes from one to the other as a new commit — rather than simply merging individual commits between the two.

    I’d envision the steps would be:

    • Create the first repository and push it to origin (I’ll assume you’re using github for now). This is the <whatever> repository in your scenario.
    • Fork the repository. This becomes the <*my_other_repository*> repository.
    • Then commit changes as you want in whichever repository you want.
    • Then ‘pull’ changes between them as you want.

    This approach gives you a lot of flexibility when ensuring that all the commits go between repositories easily and intact. (In your scenario above, commits in the new repository actually become different git commits — this can lose information about each individual commit in some cases.)

    Another benefit to this approach is that it’s pretty easy to expand to having 3, 4, 5 or however many other repositories instead of just 2. You can also designate one person to handle merges to the main repository so they can act as ‘traffic cop’ and reject some changes if it makes sense.

    Best of luck –

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