Skip to content
Fix Code Error

How do you clone a Git repository into a specific folder?

March 13, 2021 by Code Error
Posted By: BigDave

Executing the command git clone [email protected]: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?

Solution

Option A:

git clone [email protected]:whatever folder-name

Ergo, for right here use:

git clone [email protected]:whatever .

Option B:

Move the .git folder, too. Note that the .git folder is hidden in most graphical file explorers, so be sure to show hidden files.

mv /where/it/is/right/now/* /where/I/want/it/
mv /where/it/is/right/now/.* /where/I/want/it/

The first line grabs all normal files, the second line grabs dot-files. It is also possibe to do it in one line by enabling dotglob (i.e. shopt -s dotglob) but that is probably a bad solution if you are asking the question this answer answers.

Better yet:

Keep your working copy somewhere else, and create a symbolic link. Like this:

ln -s /where/it/is/right/now /the/path/I/want/to/use

For your case this would be something like:

ln -sfn /opt/projectA/prod/public /httpdocs/public

Which easily could be changed to test if you wanted it, i.e.:

ln -sfn /opt/projectA/test/public /httpdocs/public

without moving files around. Added -fn in case someone is copying these lines (-f is force, -n avoid some often unwanted interactions with already and non-existing links).

If you just want it to work, use Option A, if someone else is going to look at what you have done, use Option C.

Answered By: Can Berk Güder

Related Articles

  • How to solve Internal Server Error in Next.Js?
  • Good way of getting the user's location in Android
  • How can I commit files with git?
  • Git Using Remote Branch
  • What is your most productive shortcut with Vim?
  • Is it safe to shallow clone with --depth 1, create…
  • Vue.JS & Spring Boot - Redirect to homepage on 404
  • How to track untracked content?
  • Why do git fetch origin and git fetch : behave differently?
  • How do I clone a single branch in Git?
  • Why do I have to "git push --set-upstream origin "?
  • Push on GIT and Bitbucket
  • typescript - cloning object
  • What are the undocumented features and limitations…
  • git pull while not in a git directory
  • Pass props in Link react-router
  • ExpressJS How to structure an application?
  • How can I show current location on a Google Map on…
  • How to get current location in Android
  • How to get the current location latitude and…
  • Apache server keeps crashing, "caught SIGTERM,…
  • How do I pass a unique_ptr argument to a constructor…
  • Multipart File Upload Using Spring Rest Template +…
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • bootstrap-datepicker in dd/mm/yyyy - selected date…
  • How to pull in changes from skeleton sub-repository…
  • Why does git say "Pull is not possible because you…
  • Error message "Forbidden You don't have permission…
  • How do I adb pull ALL files of a folder present in SD Card
  • Why does Git say my master branch is "already up to…
  • Android Location Providers - GPS or Network Provider?
  • Using two values for one switch case statement
  • What is the simplest and most robust way to get the…
  • How to recover stashed uncommitted changes
  • Error creating bean with name
  • Actix: what's the right way to move shared data into…
  • Git submodule update
  • Relational room database: The class must be either…
  • What exactly does the "u" do? "git push -u origin…
  • Runing vue/cli app under docker simple index.html is opened
  • What's the difference between git clone --mirror and…
  • How do you get git to always pull from a specific branch?
  • Various ways to remove local Git changes
  • Git workflow and rebase vs merge questions
  • How to filter a RecyclerView with a SearchView
  • Can't navigate in google maps activity it always…
  • Geofire query events not firing
  • Importing a GitHub project into Eclipse
  • GIT clone repo across local file system in windows
  • How to loop back to start of question in case of…
  • Smart way to truncate long strings
  • Why call git branch --unset-upstream to fixup?
  • Checkout another branch when there are uncommitted…
  • Start redis-server with config file
  • How do I clone into a non-empty directory?
  • How do I install Java on Mac OSX allowing version switching?
  • How can I find the product GUID of an installed MSI setup?
  • Tkinter understanding mainloop
  • Identifying and solving…
  • Git command to show which specific files are ignored…
  • How to enable mod_rewrite for Apache 2.2
  • Individual click handlers in v-for loop
  • git lfs push to github failure on Ubuntu 18.04
  • Hibernate: ids for this class must be manually…
  • Neither BindingResult nor plain target object for…
  • Checkbox filtering with VueJS
  • What is "git remote add ..." and "git push origin master"?
  • Retrieve specific commit from a remote Git repository
  • Upload video files via PHP and save them in…
  • Requested bean is currently in creation: Is there an…
  • How to set width of mat-table column in angular?
  • How to check file MIME type with javascript before upload?
  • Does "git fetch --tags" include "git fetch"?
  • Spring 3.0: Unable to locate Spring NamespaceHandler…
  • Use SQL Server Management Studio to connect remotely…
  • How can I duplicate slots within a Vuejs render function?
  • Recommended way to save uploaded files in a servlet…
  • How to specify line breaks in a multi-line flexbox layout?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • org.springframework.beans.factory.NoSuchBeanDefiniti…
  • Why is Git better than Subversion?
  • When is a move constructor called in practice?
  • Detach (move) subdirectory into separate Git repository
  • Why is Ember throwing "Uncaught Error: Assertion…
  • Best practice for Django project working directory structure
  • How to clone ('fork') your own personal GitHub repo…
  • TypeError: Cannot read property 'pathname' of null
  • How can I fix MySQL error #1064?
  • What is git tag, How to create tags & How to…
  • How do I make a Git commit in the past?
  • How to paste yanked text into the Vim command line
  • How to unescape a Java string literal in Java?
  • Logging best practices
  • Web Application Problems (web.config errors) HTTP…
  • How to request Location Permission at runtime
  • What is WEB-INF used for in a Java EE web application?
  • Ukkonen's suffix tree algorithm in plain English
  • How to backup a local Git repository?
  • How can I move all the files from one folder to…
  • How can I find the location of origin/master in git,…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to make a new List in Java

Next Post:

How to format numbers as currency string?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error