What is the difference between doing (after mkdir repo
and cd repo
):
git init
git remote add origin git://github.com/cmcculloh/repo.git
git fetch --all
git pull origin master
and
git clone git://github.com/cmcculloh/repo.git
I mean, obviously one is shorter, but other than that are they basically doing the same thing?
In laymen language we can say:
Hmm, what's missing to see the remote branch "4.2" when I pull, as I do when I clone? Something's clearly not identical.
tmp$ mkdir some_repo
tmp$ cd some_repo
some_repo$ git init
Initialized empty Git repository in /tmp/some_repo/.git/
some_repo$ git pull https://github.ourplace.net/babelfish/some_repo.git
:
From https://github.ourplace.net/babelfish/some_repo
* branch HEAD -> FETCH_HEAD
some_repo$ git branch
* master
vs
tmp$ rm -rf some_repo
tmp$ git clone https://github.ourplace.net/babelfish/some_repo.git
Cloning into 'some_repo'...
:
Checking connectivity... done.
tmp$ cd some_repo
some_repo$ git branch
* 4.2
git clone is used for just downloading exactly what is currently working on the remote server repository and saving it in your machine's folder where that project is placed. Mostly it is used only when we are going to upload the project for the first time. After that pull is the better option.
git pull is basically a (clone(download) + merge) operation and mostly used when you are working as teamwork. In other words, when you want the recent changes in that project, you can pull.
git clone
is how you get a local copy of an existing repository to work on. It's usually only used once for a given repository, unless you want to have multiple working copies of it around. (Or want to get a clean copy after messing up your local one...)
git pull
(or git fetch
+ git merge
) is how you update that local copy with new commits from the remote repository. If you are collaborating with others, it is a command that you will run frequently.
As your first example shows, it is possible to emulate git clone
with an assortment of other git commands, but it's not really the case that git pull
is doing "basically the same thing" as git clone
(or vice-versa).
clone: copying the remote server repository to your local machine.
pull: get new changes other have added to your local machine.
This is the difference.
Clone is generally used to get remote repo copy.
Pull is used to view other team mates added code, if you are working in teams.
git clone
means you are making a copy of the repository in your system.
git fork
means you are copying the repository to your Github account.
git pull
means you are fetching the last modified repository.
git push
means you are returning the repository after modifying it.
In layman's term:
git clone
is downloading and git pull
is refreshing.
While the git fetch
command will fetch down all the changes on the server that you don’t have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself. However, there is a command called git pull
which is essentially a git fetch
immediately followed by a git merge
in most cases.
Read more: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Pulling
Miss Clone: I get a fresh copy to local.
Mr Pull: I already have it locally, I just update it.
Miss Clone: I can do what you do! You are just my subset.
Mr Pull: Ditto!
Miss Clone: No, you don't create. This is what I do:
You only do #3, and then you merge, which I do not need to do(mine is fresh).
Mr Pull: Smarty pants, no big deal, I will do a "git init" first! Then we are the same.
Miss Clone: No dear, don't you need a 'checked-out branch'... the git checkout
? Who will do it? me!
Mr Pull: Oh right, that is needed. I need a default branch to act on. But..but I have the extra 'merge' capability on existing repo! Which makes me the most used command in Git ;)
Git creators: Hold your horses Mr Pull, if --bare or --mirror is used with clone or init, your merge won't happen. It remains read-only. And for you Miss Clone, git checkout
can be replaced with a git fetch <remote> <srcBranch>:<destBranch>
unless you want to use a -s <strategy>
with pull which is missing in fetch.
Miss Clone: Somehow I feel like a winner already but let me drop this too: my command applies to all the branches in the repository. Are you that broad minded Mr. Pull?
Mr. Pull: I am broad minded when it comes to fetching all the branch names from the repo. But the merge will happen only on the current checked out branch. Exclusivity is the name! And in your case too, you only check-out one branch.
git clone URL ---> Complete project or repository will be downloaded as a seperate directory. and not just the changes git pull URL ---> fetch + merge --> It will only fetch the changes that have been done and not the entire project
git clone <remote-url>
<=>
git init
// init new repositorygit remote add origin <remote-url>
// add remotegit fetch
// fetch all remote branchsgit switch <default_branch>
// switch to the default branchgit pull
<=>
git pull <remote> <branch>
<=>
Clone-: It will create exactly duplicate copy of your remote repository project in your local machine.
Pull-: Suppose two or more than two people are sharing the same repository. (Suppose another person name is Syam) (A Repository is a place where your project exist in Github) So if Syam does some changes in the same project in his local and pushes it to the remote repository So whatever the changes Syam did those changes will not reflect in your local. So to reflect those new changes in your local you have to use git pull. Overall we use git pull to update the project.
So basically we use git clone only once whereas we use git pull many times.
Source: Stackoverflow.com