How do you clone a Git repository into a specific

2019-01-03 03:23发布

Executing the command git clone git@github.com:whatever creates a directory in my current folder named whatever, and drops the contents of the Git repository into that folder:

/httpdocs/whatever/public

My problem is that I need the contents of the Git repository cloned into my current directory so that they appear in the proper location for the web server:

/httpdocs/public

I know how to move the files after I've cloned the repository, but this seems to break Git, and I'd like to be able to update just by calling git pull. How can I do this?

16条回答
forever°为你锁心
2楼-- · 2019-01-03 04:23

To clone git repository into a specific folder, you can use -C <path> parameter, e.g.

git -C /httpdocs clone git@github.com:whatever

Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax:

git git@github.com:whatever .

Note that cloning into an existing directory is only allowed when the directory is empty.

Since you're cloning into folder that is accessible for public, consider separating your Git repository from your working tree by using --separate-git-dir=<git dir> or exclude .git folder in your web server configuration (e.g. in .htaccess file).

查看更多
Luminary・发光体
3楼-- · 2019-01-03 04:25
For Windows user 

1> Open command prompt.
2> Change the directory to destination folder (Where you want to store your project in local machine.)
3> Now go to project setting online(From where you want to clone)
4> Click on clone, and copy the clone command.
5> Now enter the same on cmd .

It will start cloning saving on the selected folder you given .
查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-03 04:28

When you move the files to where you want them, are you also moving the .git directory? Depending on your OS and configuration, this directory may be hidden.

It contains the repo and the supporting files, while the project files that are in your /public directory are only the versions in the currently check-out commit (master branch by default).

查看更多
冷血范
5楼-- · 2019-01-03 04:28

Regarding this line from the original post:

"I know how to move the files after I've cloned the repo, but this seems to break git"

I am able to do that and I don't see any issues so far with my add, commit, push, pull operations.

This approach is stated above, but just not broken down into steps. Here's the steps that work for me:

  1. clone the repo into any fresh temporary folder
  2. cd into that root folder you just cloned locally
  3. copy the entire contents of the folder, including the /.git directory - into any existing folder you like; (say an eclipse project that you want to merge with your repo)

The existing folder you just copied the files into , is now ready to interact with git.

查看更多
登录 后发表回答