Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I have a working copy of the project, without any source control metadata. Now, I'd like to do the equivalent of git-clone into this folder and keep my local changes.

git-clone doesn't allow me to clone into an existing folder. What is the best practice here?

1 Answer

0 votes
by (62.9k points)

Don't clone, fetch instead. In the repo:

git init

git remote add origin $url_of_clone_source

git fetch origin

git checkout -b master --track origin/master # origin/master is clone's default branch

Then you can reset the tree to get back to the commit you mention in the git reset command:

git reset origin/master # or to whatever commit you want to go reset to

and you are like you cloned.

The interesting question here (and the one without the answer): How to find out which commit your naked tree was based on, hence to which position to reset to.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories