-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_github.py
More file actions
122 lines (97 loc) · 2.96 KB
/
Copy pathupload_github.py
File metadata and controls
122 lines (97 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import subprocess
import sys
def run_command(command):
try:
subprocess.run(command, check=True, shell=True)
except subprocess.CalledProcessError as e:
print(f"❌ Error running command: {command}")
sys.exit(1)
def create_gitignore():
# Standard Next.js gitignore content
content = """
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
"""
if not os.path.exists(".gitignore"):
with open(".gitignore", "w") as f:
f.write(content.strip())
print("✅ Created .gitignore file (Prevents uploading node_modules & API keys)")
else:
print("ℹ️ .gitignore already exists")
def main():
print("🚀 Starting GitHub Upload Sequence...")
# 1. Check for Git installation
try:
subprocess.run(["git", "--version"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except FileNotFoundError:
print("❌ Git is not installed. Please install Git from https://git-scm.com/downloads")
return
# 2. Setup .gitignore
create_gitignore()
# 3. Initialize Repo
if not os.path.exists(".git"):
run_command("git init")
print("✅ Initialized empty Git repository")
# 4. Add and Commit
print("⏳ Adding files to staging...")
run_command("git add .")
# Check if there are changes to commit
status = subprocess.run("git status --porcelain", shell=True, capture_output=True, text=True)
if status.stdout.strip():
print("⏳ Committing files...")
run_command('git commit -m "Initial commit of EduLearn Platform"')
print("✅ Created initial commit")
else:
print("ℹ️ No changes to commit")
# 5. Rename branch to main
run_command("git branch -M main")
# 6. Remote Setup
print("\n" + "="*50)
print("⚠️ ACTION REQUIRED: CREATE REPO ON GITHUB ⚠️")
print("1. Go to https://github.com/new")
print("2. Name your repository (e.g., 'edulearn-platform')")
print("3. Click 'Create repository'")
print("4. DO NOT add README, .gitignore, or license")
print("="*50 + "\n")
repo_url = input("👉 Paste the HTTPS URL from GitHub here: ").strip()
if not repo_url:
print("❌ No URL provided. Aborting.")
return
# 7. Add Remote & Push
try:
# Remove origin if it exists (in case of re-run)
subprocess.run("git remote remove origin", shell=True, stderr=subprocess.DEVNULL)
except:
pass
run_command(f"git remote add origin {repo_url}")
print("✅ Remote origin added")
print("🚀 Pushing code to GitHub...")
run_command("git push -u origin main")
print("\n✨ Success! Your project is live at:")
print(repo_url)
if __name__ == "__main__":
main()