Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a file in remote repo, without cloning that repo first?

Tags:

git

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.

like image 551
algal Avatar asked Apr 18 '13 08:04

algal


People also ask

Can we push without clone?

The man pages says though: you cannot clone or fetch from it, nor push from nor into it. So even though you could use this to create a patch and send the patch individually, it won't help you with pushing changes automatically. @Shahbaz, done.


2 Answers

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.

like image 144
kostix Avatar answered Sep 25 '22 19:09

kostix


Yes you can push a new version using tagging

follow this steps

in your new project root

  1. git init
  2. git remote add origin [email protected]:yourusername/yourpoject
  3. git tag -a v2.0 -m 'version 2.0'
  4. git add .
  5. git commit -m "New Version 2.0 :rocket:"
  6. 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.

like image 31
Fatih Akgun Avatar answered Sep 25 '22 19:09

Fatih Akgun