diff --git a/push_markdown.py b/push_markdown.py new file mode 100644 index 0000000..5db3cd1 --- /dev/null +++ b/push_markdown.py @@ -0,0 +1,44 @@ +import os +import sys +from git import Repo + +def clone_repo(repo_url, branch="main"): + Repo.clone_from(repo_url, ".", branch=branch) + +def create_markdown_file(file_name, content): + with open(f"{file_name}.md", "w") as f: + f.write(content) + +def commit_and_push(file_name, message): + repo = Repo(".") + repo.index.add([f"{file_name}.md"]) + repo.index.commit(message) + repo.remote().push() + +def create_new_branch(branch_name): + repo = Repo(".") + repo.create_head(branch_name).checkout() + repo.head.reference.set_tracking_url(f"https://your_git_server/{REPO_OWNER}/{REPO_NAME}.git/{branch_name}") + repo.remote().push() + +if __name__ == "__main__": + if len(sys.argv) < 3: + print("Usage: python push_markdown.py ") + sys.exit(1) + + repo_url = sys.argv[1] + file_name = sys.argv[2] + + # Clone the repository + clone_repo(repo_url) + + # Create a new Markdown file with content + create_markdown_file(file_name, "Hello, World!\n") + + # Commit and push changes to the main branch + commit_and_push(file_name, f"Add {file_name}.md") + + # Create a new branch named after the Markdown file + create_new_branch(file_name) + + print(f"Successfully created '{file_name}' branch with '{file_name}.md'.")