When would you use git clone over git clone –bare?

Technology CommunityCategory: GitWhen would you use git clone over git clone –bare?
VietMX Staff asked 3 years ago

Suppose origin has a few branches (master (HEAD)nextpu, and maint), some tags (v1v2v3), some remote branches (devA/masterdevB/master), and some other refs (refs/foo/barrefs/foo/baz, which might be notes, stashes, other devs’ namespaces, who knows).

  • git clone (non-bare): You will get all of the tags copied, a local branch master (HEAD) tracking a remote branch origin/master, and remote branches origin/nextorigin/pu, and origin/maint. The tracking branches are set up so that if you do something like git fetch origin, they’ll be fetched as you expect. Any remote branches (in the cloned remote) and other refs are completely ignored.
  • git clone --bare: You will get all of the tags copied, local branches master (HEAD)nextpu, and maint, no remote tracking branches. That is, all branches are copied as is, and it’s set up completely independent, with no expectation of fetching again. Any remote branches (in the cloned remote) and other refs are completely ignored.

To summarize,

  • git clone is used when we need to point to an existing repo and make a clone or copy of that repo at in a new directory.
  • git clone --bare is used to make a copy of the remote repository with an omitted working directory.