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.
You can do it by typing the following command lines recursively:
mkdir temp_dir // Create new temporary dicetory named temp_dir
git clone https://www...........git temp_dir // Clone your git repo inside it
mv temp_dir/* existing_dir // Move the recently cloned repo content from the temp_dir to your existing_dir
rm -rf temp_dir // Remove the created temporary directory
This is the Best of all methods i came across
Clone just the repository's .git folder (excluding files as they are already in existing-dir
) into an empty temporary directory
git clone --no-checkout repo-path-to-clone existing-dir/existing-dir.tmp
//might want --no-hardlinks for cloning local repoMove the .git folder to the directory with the files.
This makes existing-dir
a git repo.
mv existing-dir/existing-dir.tmp/.git existing-dir/
Delete the temporary directory
rmdir existing-dir/existing-dir.tmp
cd existing-dir
Git thinks all files are deleted, this reverts the state of the repo to HEAD.
WARNING: any local changes to the files will be lost.
git reset --mixed HEAD
To clone a git repo into an empty existing directory do the following:
cd myfolder
git clone https://myrepo.com/git.git .
Notice the .
at the end of your git clone
command. That will download the repo into the current working directory.
if you are cloning the same repository, then run the following snippet through the existing repository
git pull origin master
Usually I will clone the initial repository first, and then move everything in the existing folder to the initial repository. It works every time.
The advantage of this method is that you won't missing anything of the initial repository including README or .gitignore.
You can also use the command below to finish the steps:
$ git clone https://github.com/your_repo.git && mv existing_folder/* your_repo
Using a temp directory is fine, but this will work if you want to avoid that step. From the root of your working directory:
$ rm -fr .git
$ git init
$ git remote add origin your-git-url
$ git fetch
$ git reset --mixed origin/master