Reputation: 12343
Have an existing repo in git-hub with the projects files.
On a new machine, got into the target directory, e.g. myproject, and do this:
$ git init
$ git remote add origin https://github.com/myco/myproj.git
$ git pull (this downloads lots of files)
$ ls (no files)
$ git branch --set-upstream master origin/master
$ ls (no files)
$ git status ( shows all the files are marked for deletion! )
I have used this recipe before, no idea why doing a checkout of a repo causes it to delete all the repos files.
If I try and do the git branch before the git pull, it gives an error.
I cant use git clone, as ultimately, I need to have the files checked out into an eisting directory which already will have some project donfig files (not in git).
Any ideas?
Upvotes: 0
Views: 63
Reputation: 62379
If that is in fact the exact sequence of commands you followed, then here are some comments to help you understand where you are:
$ git init
Since it seems like you entered an empty directory (on a new machine, ...), this creates a new repository out of your current directory. This repository has no objects, no master
branch yet, no commits, etc...
$ git remote add origin https://github.com/myco/myproj.git
This adds your origin repository and shouldn't be a problem.
$ git pull (this downloads lots of files)
This does two things - git fetch
to collect all objects, branches, etc. that your origin
repository currently has but your local repository doesn't (i.e. everything, since you're in a currently empty repository), followed by git merge
. The merge
phase should have failed here, with a message the the effect of "you didn't tell me what you want to merge, so I'm not going to do it".
$ ls (no files)
Right. You still haven't checked anything out, and since the git merge
above failed, it never got to the point of updating your working directory.
$ git branch --set-upstream master origin/master
Now you are creating a master
branch that has origin/master
as its upstream, and as its starting point. However, this does not check out the branch, which leaves your working directory in the same state it was before, i.e. empty.
$ ls (no files)
You still have not checked anything out, so this is expected.
$ git status ( shows all the files are marked for deletion! )
git
compares your empty working directory with what it thinks should be there, and determines that you must have removed everything.
What you really wanted to do there is this:
$ cd directory/where/you/want/your/repository
$ git clone https://github.com/myco/myproj.git
$ cd myproj
Then, copy your additional project config files into place.
If you really want to do it all the manual way, use git fetch
instead of git pull
, and after your git branch ...
line, do a git checkout master
(or do git checkout -b master origin/master
in place of the git branch ...
line, which implicitly does the branch setup before checking out the files).
Upvotes: 1