Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a file to a git repo without having it checked out locally?

Tags:

git

github

Goal: Add a new file to a remote git repository without checking the whole thing out locally.

Why: I'm building an app that will add files to a user's git repository. Some of these repositories will be hundreds of megs. Some will be touched very infrequently. I want to avoid taking up terabytes of disk space to keep large repos checked out that won't be touched often, and I don't want to incur the inevitable delay of checking out a 200Mb repo (lots of binary files) in order to add a new one new file to it and push that file back to the origin.

I'm assuming the default git client can NOT do this, but am hoping that someone has written something that can commit to a remote repo (don't care what language) without having the whole thing checked out locally. Does the Cloud9 IDE do something like this?

The app would have full access to the users git repo, either via SSH or whatever mechanism GitHub uses for oAuthed apps to tweak repos.

like image 740
masukomi Avatar asked Dec 24 '11 16:12

masukomi


People also ask

How do I add files to an existing git repository?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

Can GitHub be used to track project files without having git installed?

Git is an open-source, version control tool created in 2005 by developers working on the Linux operating system; GitHub is a company founded in 2008 that makes tools which integrate with git. You do not need GitHub to use git, but you cannot use GitHub without using git.

What does it mean to add a file to git?

git add [filename] selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit. This means if you git add a deleted file the deletion is staged for commit.


2 Answers

Depending on the structure of your repository, you may be able to use sparse checkouts to avoid downloading the large files:

http://schacon.github.com/git/git-read-tree.html#_sparse_checkout

(More information at Checkout subdirectories in Git?)

like image 165
cmbuckley Avatar answered Oct 14 '22 05:10

cmbuckley


Git has several options for shallow cloning and filepath specific, partial cloning but these are not pushable.

The trick here is to utilize the --lightweight flag when you checkout - in which case, you will be able to push to a limited repository.

However, these solutions appear severely nonideal... Seems more intuitive that , If the app has programmatic access to a git repository, then you should be able to create, or require on installation the creation of a git project that is specific to your application's needs, which is empty.

like image 2
jayunit100 Avatar answered Oct 14 '22 07:10

jayunit100