I have a working copy of the project, without any source control meta data. Now, I\'d like to do the equivalent of git-clone into this folder, and keep my local changes.
git clone your_repo tmp && mv tmp/.git . && rm -rf tmp && git reset --mixed
I'd git clone
to a new directory and copy the content of the existing directory to the new clone.
Just use the . at the end of the git clone
command (being in that directory), like this:
cd your_dir_to_clone_in/
git clone git@github.com/somerepo/ .
The following i did, to checkout master branch in an existing directory:
git init
git remote add origin [my-repo]
git fetch
git checkout origin/master -ft
If you are using at least git 1.7.7 (which taught clone
the --config
option), to turn the current directory into a working copy:
git clone example.com/my.git ./.git --mirror --config core.bare=false
This works by:
.git
folder--mirror
makes the new clone into a purely metadata folder as .git
needs to be--config core.bare=false
countermands the implicit bare=true
of the --mirror
option, thereby allowing the repository to have an associated working directory and act like a normal cloneThis obviously won't work if a .git
metadata directory already exists in the directory you wish to turn into a working copy.
Lots of answers already to do it the way that the OP asked. But it worth noting that doing it the opposite way around is far simpler:
git clone repo-url tmp/
cp -R working/ tmp/
You now have the desired target state - fresh clone + local-changes.