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.<
The repo includes a collection of rather fatty binary files
That is not what a git repo is designed to do, as I explained here.
You can't push something without having fetched first, so unless your repo is hosted in a service which supports adding files through its web interface (like GitHub, as commented by heinrich5991), you won't be able to import just one file.
One alternative would be to have a dedicated server hosting a full copy of your repo at all time, to which you could add one file, and from which you could then push to the target repo.
There is no way to do that. I just made a test following:
mkdir hello_independent
(note:"hello" is my previous repository's name)git init
(note:create a repository with blank here)git remote set-url origin https://github.com/solio/GitPractice.git
(note:set the local repository point to the remote repository.)vim newfilefromindependentfolder.md
(note:add a new file)git add --a
git commit -m "test commit from independent folder."
git push origin master
(note:this operation is the key)it will show this error:(sorry I can't upload the image of my operation and hint message without 10 reputation)
here is my comprehension of the message:when I do this there are two different independent workflow,they have nothing relationship.So when you want to commit the independent files to the remote repository you must merge the local repository and the remote.So the best way to solve this is git clone the remote repository.
For GitHub at least (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 like above to https://api.github.com/repos/:owner/:repo/contents/:path
If it succeeds, you get a JSON response back that includes the GitHub URL(s) for the created file.
Can also update files without cloning: https://developer.github.com/v3/repos/contents/#update-a-file