My question is when we do git pull how are different files downloaded? I mean are we going to download the .git folder first then the project files or reverse? Are files will be zipped in some format when downloaded and then unzipped or are they downloaded as separate files? Please also explain if there is any difference between the first pull or later git fetch?
CodePudding user response:
when we do git pull how are different files downloaded? I mean are we going to download the .git folder first then the project files or reverse?
Neither. Git does not traffic in files. It traffics in commits. Every commit is a snapshot of the state of all your files. And every commit is uniquely identified: not just on your computer but throughout the universe. And every file state is uniquely identified: not just on your computer but throughout the universe.
Therefore when you say git pull origin mybranch
, or a shortened version of that, Git on your machine talks to Git on the remote server and ascertains which commits are reachable on this branch on the remote server but not on your local machine, and transfers just those commits.
Moreover, the transfer can save space (bandwidth). If a commit to be transferred refers to ("contains") a certain file in a certain state, and if another commit to be transferred refers to that same file in that same state, the remote Git knows that you don't need another copy of that same data. And if you already have a commit that refers to a certain file in a certain state, and if a commit to be transferred refers to that same file in that same state, the remote Git, which knows what commits you already have, knows that you don't need another copy of that same data.