-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear-commits.py
More file actions
28 lines (21 loc) · 813 Bytes
/
clear-commits.py
File metadata and controls
28 lines (21 loc) · 813 Bytes
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
import subprocess
def run_command(command):
"""Run a command in the shell and print the output."""
try:
result = subprocess.run(command, check=True, text=True, capture_output=True)
print(result.stdout)
except subprocess.CalledProcessError as e:
print(f"Error: {e.stderr}")
exit(1)
# Switch to a new orphan branch
run_command(["git", "checkout", "--orphan", "new_branch"])
# Stage all changes
run_command(["git", "add", "."])
# Commit changes
run_command(["git", "commit", "-m", "new_commit"])
# Delete the old main branch
run_command(["git", "branch", "-D", "main"])
# Rename the new branch to main
run_command(["git", "branch", "-m", "main"])
# Force push to the remote main branch
run_command(["git", "push", "-f", "origin", "main"])