使用curl将文件推送到GitHub存储库

Mor*_*adi 5 curl github-api github-pages gitlab-api

我想在没有工具的情况下在 GitHub 存储库上创建(推送)新文件git(因为该git工具在我的主机上不可用PHP)。所以我做了一些研究,发现了GitHub REST API

我尝试使用curl个人访问令牌来上传或修改我的存储库上的文件。这是我找到的 shell 代码,并进行了curl如下更改:

curl -i https://api.github.com/repos/username/repo/newFile.txt -X PUT 
\ -H 'Authorization: token xxxxxxxxxxxxxxxxxxxx' -d "{\"path\": \"newFile.txt\", 
\ \"message\": \"update\", \"content\": \"$(openssl base64 -A -in newFile.txt)\", \"branch\": 
\"master\",
\ \"sha\": $(curl -X GET https://api.github.com/repos/username/repo/newFile.txt  | jq .sha)}" 
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

HTTP/1.1 404 未找到

服务器:GitHub.com

我该如何解决这个问题?

PS 即使push file by emailGitHub 或 (GitLab) 上有服务,这也可以帮助通过电子邮件在我的存储库上创建文件。

Von*_*onC 2

它应该是“创建或更新文件内容”端点 API:

\n
PUT /repos/{owner}/{repo}/contents/{path}\n
Run Code Online (Sandbox Code Playgroud)\n

contents(我在你的网址中没有看到https://api.github.com/repos/username/repo/newFile.txt

\n

确保使用最近的 PAT(个人访问令牌),如此处所示
\n还有一个例子

\n
#! /bin/bash\n \ncartella= " /var/myfolder "\n \n# update the file\ncurl -i -X \xe2\x80\x8b\xe2\x80\x8bPUT -H \' Authorization: token 4d013330xxxxxxxxxxxxxxx \' -d " { \\" path \\" : \\" mattei.csv \\" , \\\n\\" message \\" : \\" update \\" , \\" content \\" : \\" $( openssl base64 -A -in $cartella /mattei.csv ) \\" , \\" branch \\" : \\" master \\" , \\\n\\" sha \\" : $( curl -X GET https://api.github.com/repos/username/repo/contents/mattei.csv | jq .sha ) } " \\\nhttps://api.github.com/repos/username/repo/contents/mattei.csv\n
Run Code Online (Sandbox Code Playgroud)\n