2

I know that we can clone a repository from a remote repo like GitHub (or any Git server) and then pull/push.

Suppose a colleague of mine clones a Git repo (or creates a Git repo using git init). Can I add my colleague's repo as a remote repo on my PC and clone/pull/push changes to my colleague's repo?

If so, then is any computer a Git server? Or do we need to install something to make it a Git server?

user229044
  • 232,980
  • 40
  • 330
  • 338
variable
  • 8,262
  • 9
  • 95
  • 215
  • Any Git directory is a "Git server", in that it can be cloned from. If you make that Git directory available over a network, then the server hosting the directory is a "Git server" in that somebody could clone the repository, but there's no Git-specific server software at play. – user229044 Jan 26 '20 at 01:17

2 Answers2

2

You can, using the local protocol: it supposes you have a shared folder on your colleague computer that you can access.

git clone //server/share/path/to/repo

If you are on Windows, the UNC path support has recently (Git 2.21, Q1 2019) been improved.

A Git "server" is Git + a listener (SSH or HTTPS server).
That listener can add authentication or even authorization in some case.

But Git itself manages files (file history). It is not a server.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So any computer is a GIT server? – variable Jan 25 '20 at 06:43
  • @variable Git itself is not a server. Only a listener (ssh or https) would make it a server. Git manages files. Including files accessed through the shared filesystem. – VonC Jan 25 '20 at 06:53
  • Ok so the GIT repo itself acts like a server? – variable Jan 29 '20 at 10:32
  • @variable The Git repository itself is just a collection of files, managed by the tool git. For a "server" to exist, you need a listener (SSH or HTTPS) which will in turn call Git. That is what https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols describes. Example for an HTTPS server (calling Git): https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP – VonC Jan 29 '20 at 11:21
1

Yes, that's one of the core principles of git : it's distributed.

It means that no repo is central in and of itself. When a team uses an online git platform like github/bitbucket, it's only a choice of convenience, which could be revoked at any time for another workflow if needed.

(For that matter, you could as well have a repo on your machine, then clone it on the same machine, then pull/push between these two.)

As a sidenote, even if not at the heart of your question, something else lures some people into thinking that their online repo is "different" than the local ones : it's the fact that you can have full clones or bare clones. Bare clones are limited, mostly by having no worktree and been only interacted with by pull/push. Github repos are like that, and many teams use a bare repo in a centralized role. Thus the confusion.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • So any computer is a GIT server? – variable Jan 25 '20 at 06:43
  • Any *repo* is. You can have multiple ones of the same computer. The condition is, yes, to have git installed on the machine. Then it can have as many repos as you want, and as many clones of each repo as you want. – Romain Valeri Jan 25 '20 at 06:51