0

I have read about the difference between remote and clone, eg: Difference between git remote add and git clone

But I'm wondering when in practice I should opt for git remote. (I'm working on a server with no internet; we use git bare as a github alternative.)

I assume if I create a bare repo (empty) and then clone it, this would produce the same result as creating a repo, and then creating a bare repo, and pointing the former to the latter using git remote. Therefore, if I'm setting up a project, git remote feels more clumsy than cloning.

I might use it, however, if a single programmer has already written some code (and others are joining after the project has started). Rather than copy the programs to a new repo (resulting from cloning a new bare repo), they could use git remote to push/pull to the new bare repo, and programmers joining the project can clone the bare repo.

Does this make sense? My goal is to do things in the cleanest and simplest way.

[Edited: punctuation.]

  • It's not really clear what you think the difference is. You would use `clone` in virtually all cases, `remote` is for adding an additional remote. There is no reason to choose between the two, neither has anything specific to do with bare repos, they are not competing commands, they do completely different things. – user229044 Aug 15 '22 at 10:28
  • I'd use `git remote add` if I started out with a local repo and wanted to push it somewhere else. It entirely depends on what you start with. – evolutionxbox Aug 15 '22 at 10:28
  • This question is answerable (the use case is unclear, but the central question is answerable). It was closed too fast, I already had an answer 99% typed out – knittl Aug 15 '22 at 10:32
  • If you want to run both `git init` *and* `git remote add`, and then also run `git fetch` and perhaps some other things, *then* you use `git clone`. If you don't want to run `git init` at all, then you don't use `git clone`. – torek Aug 15 '22 at 10:36

2 Answers2

1

I'm not really following the use case that you are describing, but in any case, the following two are roughly equivalent (the end result is the same):

  1. git clone path/or/url/to/your/repo.git
    
  2. cd repo
    git init
    git remote add origin path/or/url/to/your/repo.git
    git fetch
    

The former being definitely easier to remember and fewer key strokes.

knittl
  • 246,190
  • 53
  • 318
  • 364
1

Another use case of git remote add is when you have multiple upstream for a single repository.

For example, a common use case when working with Github is to have a fork repository in your account, and have both original and your fork added as remotes in your local copy. This way you can push to your own remote fork and keep track of changes in the original remote repository at the same time in a single repository.

Another example of this can be using a USB memory stick as a backup remote repository. After cloning from a remote Github repository, you can create a bare repo in a USB folder and add this folder as another remote to the same working copy. Then, you can frequently push to USB as a backup when working offline, for example.