Skip to content

Instantly share code, notes, and snippets.

@Arifursdev
Last active November 25, 2025 09:25
Show Gist options
  • Select an option

  • Save Arifursdev/034a046e031008f8e2bf2dab369ba638 to your computer and use it in GitHub Desktop.

Select an option

Save Arifursdev/034a046e031008f8e2bf2dab369ba638 to your computer and use it in GitHub Desktop.
clone git repo without .git folder
import os
import shutil
import subprocess
# Define temp folder name
temp_folder = "unique_temp_folder_12345"
repo_url = "https://github.com/username/abcd.git"
# Clone repo to temp folder
subprocess.run(["git", "clone", repo_url, temp_folder], check=True)
# Delete .git folder in temp folder
git_folder = os.path.join(temp_folder, ".git")
if os.path.exists(git_folder):
subprocess.run([
"powershell.exe",
"Remove-Item",
"-Force",
"-Recurse",
"-Path",
git_folder
], check=True)
# Copy all files from temp folder to current folder
def copy_contents(src_dir, dest_dir):
for root, dirs, files in os.walk(src_dir):
rel_path = os.path.relpath(root, src_dir)
dest_root = os.path.join(dest_dir, rel_path) if rel_path != '.' else dest_dir
if not os.path.exists(dest_root):
os.makedirs(dest_root)
for file in files:
src_file = os.path.join(root, file)
dest_file = os.path.join(dest_root, file)
shutil.copy2(src_file, dest_file)
# Copy all files and folders from temp_folder to current folder
copy_contents(temp_folder, os.getcwd())
# Remove temp folder after copying
shutil.rmtree(temp_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment