5

I have downloaded an archive of some large GitHub repository using Download ZIP link. It contained just the source code, so it wasn't a clone or a git repo anymore. Then I made some changes in this code on my disk and now I want to update it using the code of HEAD revision from the original GitHub repo (which has changed since I downloaded the ZIP file). But it's a large repo, so I don't want to download all the files, but just the modified ones.

Should I git init a new repo in my existing source code folder, then git add . and git commit then git remote add origin https://github.com/someuser/someproject.git and git pull origin master? Will this download only the modified files?

niutech
  • 28,923
  • 15
  • 96
  • 106

2 Answers2

2

Will this download only the modified files?

No, Git always works with all the files of a repo. In your case, git pull against an almost empty repo (only one revision) would still fetch all the revisions.

It is really easier to simply clone the repo (even if it is a large one), and copy over your modification, git add, commit and push: that will push only the modified files.

From Git 1.9.0, you could consider a shallow clone (cloning only the last revision), since you now can push from said shallow clone.
See "How to git fetch efficiently from a shallow clone".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So does `git pull` always download the whole repo, even if the local files are unmodified? – niutech Mar 04 '14 at 22:59
  • @niu no, git clone does. git pull only pull the delta. – VonC Mar 05 '14 at 04:31
  • Then why do you state in your answer that `git pull` won't download only the modified files? I don't want to clone a repo, but rather init a local repo and merge it with the remote one, so that only changed files (deltas) would be downloaded. Is it possible? – niutech Mar 05 '14 at 12:45
  • @niutech Because it would still fetch the all history. Git needs the history in order to detect changes against said history and push the delta. Note that since git 1.9.0, you can try a shallow clone (clone only the last revision instead of the full history): http://stackoverflow.com/a/21217326/6309. That could be a solution for you. See my edited answer. – VonC Mar 05 '14 at 12:53
0

It is easier to make a clone and commit/push your changes. If you do not know how to use Git see this:

http://try.github.io/levels/1/challenges/1

Edgar Peixoto
  • 543
  • 1
  • 5
  • 23