Reputation: 28094
Is there a way to push a commit to a remote git repo, without first making a local clone of that repo?
I have a valid URL for the remote repo, I know the path of the file, and all I want to do is push an updated version of the file onto the master. Ideally I'd like this to work with any valid remote repo URL, but it would still be helpful if it worked only with https-based git URLs.
I'm guessing this is impossible, since it does not seem to be possible even to retrieve a single file without cloning in the general case, according to the answer How to "git show" on a remote repo? . But I'm hoping there's a workaround that uses some of the lower level git commands.
Upvotes: 41
Views: 34286
Reputation: 32226
I haven't tested it yet, but here is an idea.
Create a new repo with no files and commit it with a message "day 1".
Next, add all the other commits and the rest of your project.
Now check out that "day 1" and create a branch out of it.
Do a shallow copy clone to this branch with --depth 1
, it should be very light.
Now finally, add your new file and create a PR to your main branch via Github APIs.
Done!
Same strategy as the new file, only now you will end up with a conflict. You can potentially avoid it with an auto rebase resolution, not sure how to do it on a PR level so...
Upvotes: 0
Reputation: 57
If you are using Github you can use the Github Web Editor. The most easy way to update files without cloning the repo in your local is:
.
You should see Visual Studio Code running on your browser. Then, create the folders or drag and drop files from your computer
For save the changes press: Ctrl + Shift + G
or click the 'Source Control' option in the left bar, and commit the changes.
Upvotes: 1
Reputation: 2549
Well, if you use GitHub, then you could do this easily with GitHub API
https://developer.github.com/v3/repos/contents/#create-or-update-a-file
Basically you do:
Create OAuth App and get Access Token
https://developer.github.com/apps/building-oauth-apps/
Make request to GitHub API:
Set Authorization header with your Access Token (OAuth 2.0)
PUT https://api.github.com/repos/:owner/:repo/contents/:path
with JSON body like this:
{
"message": "my test commit through API",
"content": "QmFzZTY0IGVuY29kZWQgY29udGVudCBoZXJl",
"sha": "cd220ncv229f2e4a95bce426ff48b1ae6b885b3a42"
}
Where:
message - your commit message
content - updated content encoded in Base64 format
sha - sha for updating file, you can get it by API request
GET https://api.github.com/repos/:owner/:repo/contents/:path
:owner - repository owner
:repo - repository name
:path - path to file within repository
Example request:
https://api.github.com/repos/nodejs/node/contents/README.md
Upvotes: 5
Reputation: 83
Just discovered this issue and thought of an update.
If you're using github just prefix your repo url with https://gitpod.io#.
It's a service that allows you to update your repo online, so you can update files without cloning locally.
Upvotes: 6
Reputation: 553
Yes you can push a new version using tagging
follow this steps
in your new project root
git init
git remote add origin [email protected]:yourusername/yourpoject
git tag -a v2.0 -m 'version 2.0'
git add .
git commit -m "New Version 2.0 :rocket:"
git push -u origin v2.0
now you have a new branch called v2.0 with your new project and your master branch stays untouched. After that if you wan't you can change your default branch in your github project settings.
Upvotes: 12
Reputation: 87
@algal, for your particular use-case, you might be able to use a submodule (http://git-scm.com/docs/git-submodule). You could clone and commit to the submodule, w/o cloning the "supermodule" which could contain the "massive" code you mentioned. The supermodule could reference the submodule for the config info you mentioned.
Upvotes: 0
Reputation: 55443
Impossible. But since a prospective commit would just need to have one single commit as its parent it's possible to employ the so-called "shallow cloning" and fetch just the tip commit of the branch you need. This will bring only a minimum amount of objects from the remote. Look for the --depth
command-line option of git clone
.
Upvotes: 15
Reputation: 13097
No, I don't think that's possible. You need to clone the whole repository for this to work. Git needs to know about all the files and .git
to do its job correctly. This is why you can't just push arbitrary files like that.
Upvotes: 2