0%

Chapter 7

Remotes, Without a Server

What a Remote Really Is

You can use Git with another without using the internet. In this chapter, every repository stays inside the same practice workspace. The mechanics are real; only the distance between the repositories is small.

A working repository named garden pushes to a bare origin.git; a clone named garden-copy receives history by clone or fetch and records origin/main, all through local paths without a network.

Start with the repository you already have

The prepared garden directory is an ordinary working repository. It has committed history and a working tree you can edit. Start with commands you already know:

pwd
git status
git log

You should be in /workspace/garden. The working tree is clean, and main ends with the that added plants.txt.

A remote is another repository

A remote is a saved name and location for another Git repository. Git can exchange commits, positions, and other refs with that repository. The other repository might be on a hosting service, on a server across a network, on a removable drive, or in the next directory. “Remote” describes the relationship between repositories, not a promise that the internet is involved.

This chapter will build the following local arrangement:

/workspace/
├── garden/         ordinary working repository where you make a later commit
├── origin.git/     bare repository that stores shared history
└── garden-copy/    ordinary clone used to observe and fetch that history

garden and garden-copy will have working trees. origin.git will be a bare repository: a Git repository that stores history and refs without checking out an editable set of project files. That makes it a useful exchange point. No person edits files inside its working tree because it has no working tree.

The command git init --bare creates that kind of repository. The command git clone creates a new working repository from an existing repository. You will use both in the next lessons, after each command’s pieces are explained.

Three names that must stay separate

As the chapter builds the arrangement, keep these three names separate:

  • main is a local branch in the repository where you are standing.

  • origin will be the conventional saved name for another repository.

  • origin/main will be a remote-tracking ref: a local record of where origin’s main was at the last exchange.

The next lessons create those names and show them moving. For now, the boundary is enough: main is where you work, origin names another repository, and origin/main reports remembered information rather than becoming your editable branch.

In this chapter, what makes origin.git a remote of garden?

The useful mental model is repository to repository. A host can provide storage and collaboration around that model, but it does not change what a Git remote is.