Posted in GIT

GIT : Clone repository to the existing directory

After resetting my laptop, I just had the code backup. unfortunately.git folder got removed while copying data. Cloning the repository again sounded bad for me due to its size and the poor intermittent network connectivity. Cloning of the repository failed multiple times. This might be a situation you might be undergoing. Here is the way I did to clone the repository to existing directory with all the remote data.

This can be done for:

  1. Linking the local directory with data and remote git repository WITH data
  2. Linking the local directory with data and remote git repository WITHOUT data

Step 1: In the terminal, navigated to the appropriate directory where I had my data.

cd my/directory/

Step 2: Init the repository again, since I lost .git folder

git init

Step 3: Committed the directory

git add .
git commit -m 'cloning again'

Step 4: Added remote origin

git remote add origin https://<url_here>.git

Step 5: Pulled the remote origin

git pull origin master --allow-unrelated-histories

Step 6: Pushed the local changes to remote

git push -u origin master

Tada! I got my repository back to my previous state!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s