0

I am trying to clone my a git repository inside an existing checked out git repository and getting this failure. I've done this workflow before so I cannot figure out why it would fail now. Does anyone have any suggestions?

The git repository does exist and I can clone outside of the checked out repository in a different location

Let's say I do the following

1. cd <existing git repo clone folder>

2. git clone https://github.com/apache/cassandra
Cloning Git Repository of cassandra
Cloning into 'cassandra'...
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

What could be causing this error?

PLEASE NOTE - I DO NOT WANT TO ADD THIS REPOSITORY AS A SUBMODULE TO MY PARENT GIT REPO. I simply want to figure out how to clone the repository in an existing working folder checked out from git.

tsar2512
  • 2,826
  • 3
  • 33
  • 61
  • Did you try `git clone https://github.com/apache/cassandra.git` (note the `.git` at the end)? – Leon Jul 15 '16 at 16:30

3 Answers3

1

Have a look at git submodules This was designed exactly for this. You can find information and examples here: https://git-scm.com/book/en/v2/Git-Tools-Submodules

In your case, this might work:

 git submodule add https://github.com/apache/cassandra

In order to change the submodule to track a particular commit change directory to the submodule folder and switch branches as normal.

cd submodule
git checkout -b some_branch origin/some_branch

or for some particular tag

git checkout <version_tag>

You will need to commit this change to update.

Pankaj Daga
  • 741
  • 5
  • 16
  • I do not want to add this repository as a submodule inside my checked out git repository. I simply want to checkout the git repo in a working copy of a git repo I have already checked out – tsar2512 Jul 15 '16 at 15:37
  • Have a look at this post: http://stackoverflow.com/questions/5980960/git-repository-in-a-git-repository/5981099#5981099 – Pankaj Daga Jul 15 '16 at 15:39
  • is there any way to ensure that the submodule checks out a specific revision instead of checking out the HEAD of the repo? In that case I can possibly add as submodule. – tsar2512 Jul 15 '16 at 15:41
  • so once I commit the change after doing a git checkout . Then the next time I do a recursive git clone, it will checkout the correct revision automatically? – tsar2512 Jul 15 '16 at 15:49
  • @tsar2512 After the steps I described, you will need to commit the changes first to the parent. So, if you do a `git-status`, it should report that the submodule is modified and once you commit that, it should be fine. – Pankaj Daga Jul 15 '16 at 15:52
0

Your question sort of seems to be in conflict. You can't have a git repo within another git repo without using git submodules AFAIK.

What you could do is have a dir that is not a git repo, and clone both the repos into that dir (so don't put the repos inside each other).

You could also add the repository as a remote (using git remote add name_of_remote http://your/remote/here). Then you can checkout any branch from either repo in the same repository.

Matt Messersmith
  • 12,939
  • 6
  • 51
  • 52
0

I usually do not like to use submodules. for this case I would do the following:

1) in the main repo .gitignore the folder path where you want to store the repo the path-of-cassandra-repo/* (to ignore it)

2) in the terminal execute git clone https://github.com/apache/cassandra.git path-of-cassandra-repo/ where "path-of-cassandra-repo/" the name of the folder you want git to store the repo.

3) you are ready to go... Happy coding.

Let me know if this works for you...