This Git question is very similar to another one about SVN.
I have a repo full of big files and I need to add a single file to it. This used to be very easy in SVN.
svn import -m "Adding just a file" file_name http://path/to/svn/repo/file_name
How to achieve this simple task in Git?
For GitHub (not git
itself), the GitHub API provides a way to create a file without cloning:
https://developer.github.com/v3/repos/contents/#create-a-file
PUT /repos/:owner/:repo/contents/:path
# Parameters #
----------------------------------------------------------------
Name Type Description
------ ------ -----------------------------------------------
path string Required. The content path.
message string Required. The commit message.
content string Required. The new file content, Base64-encoded.
branch string Branch name. Default: repo's default branch.
Minimal example JSON input:
{
"message": "my commit message",
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}
So you can write a script to base64-encode the file contents, then have it use curl
or such to send some JSON as above to https://api.github.com/repos/:owner/:repo/contents/:path
If it succeeds, you get a JSON response back including the GitHub URL(s) for the created file.
Can also update without cloning: https://developer.github.com/v3/repos/contents/#update-a-file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With