国内的 GitHub 访问速度实在是太慢了,当你更新完代码,准备 push 到远程仓库的时候,总是会遇到如下错误:Failed to connect to github.com port 443 after 21046 ms: Couldn't connect to server
,所以,你就会不断的 git push ,直到成功。
在你的项目目录下,新建一个 python 文件,比如 push.py
,然后在文件中写入如下代码:
```import subprocess import time
def git_push(): while True: try: subprocess.check_call(['git', 'push']) print("Git push successful!") break except subprocess.CalledProcessError: print("Git push failed. Retrying in 5 seconds...") time.sleep(5)
def main(): subprocess.check_call(['git', 'add', '.']) subprocess.check_call(['git', 'commit', '-m', '更新']) git_push()
if name == "main": main()
```
然后,在命令行中运行 python push.py
,就可以自动 push 到远程仓库了。
至少不会在一遍一遍的敲命令行,或是点击按钮提交push了。