git: clone a repository without the project folder
When you clone a remote repository, a folder with the name of the project is created in your local working directory and then the contents of the repository is copied into that folder.
For example, if you execute:
# cd /var/www # git clone user@repository.com:/home/git/myproject.git
you will get the repository copied into ‘/var/www/myproject’; most of the times that’s not what you want.
If you don’t want that folder (myproject in the example) to be created, then you can follow one of these 2 methods (depending whether the destination folder is empty or not):
METHOD #1: The destination folder is empty:
1. Go to the folder in your local computer where you want your repository to be installed:
# cd /var/www
2. Execute the following (notice the dot at the end of the command):
# git clone user@repository.com:/home/gti/myproject.git .
METHOD #2: The destination folder is NOT empty
1. Go to the folder in your local computer where you want your repository to be installed:
# cd /var/www
2. Execute the following:
# git init # git remote add origin user@repository.com:/home/git/myproject.git # git pull origin master
Leave a Reply