0%

Remotes, Without a Server · practice

Create a Local Origin

The garden needs another repository to exchange history with. You will create that repository as a sibling directory, then give its path the conventional name origin inside garden.

Create a bare repository

git init --bare combines the repository-creation command you saw earlier with the --bare option. That option tells Git to create only the repository data: , refs, and configuration, with no checked-out working tree. The final argument is the directory to create. From /workspace/garden, ../origin.git is a to a sibling of garden.

In a path, .. means the parent directory. From /workspace/garden, it reaches /workspace; adding /origin.git names a directory inside that parent. This is a relative path because its starting point is your current directory. A path beginning with /, such as /workspace/origin.git, is an and starts at the filesystem root. Use the relative path here so the three directories can move together without changing their saved relationship.

Run:

git init --bare ../origin.git

The .git suffix is a convention for bare repository directory names. It helps a reader recognize that the directory is a repository store rather than a project working tree; Git does not require the suffix.

Save the other repository as origin

Creating origin.git does not automatically connect garden to it. git remote add records a remote in the current repository. Its first argument is the name you want to use, and its second is the other repository’s location.

origin is the conventional name for the repository a project was first shared with or cloned from. It is an ordinary name, not a special server. Save the relative sibling path under that name:

git remote add origin ../origin.git

Inspect what garden saved

git remote -v inspects saved remote entries. The option -v means verbose: show the name and location used for both fetching and pushing instead of showing only the name.

git remote -v

You should see origin twice, once marked (fetch) and once marked (push), and both lines should use ../origin.git. Those labels describe two directions of exchange; they do not mean that anything has moved yet. The bare repository is still empty, and garden still has its original two commits.

Why create origin.git with git init --bare?

You now have two repositories sitting side by side, and a name in one of them pointing at the other. Nothing has travelled between them. origin.git is still completely empty, which is what the next lesson fixes.