liveBook · Manning

Repository

As explained in Road to Kubernetes

A Git repository is a directory managed by Git that stores files, metadata, and version history.

A Git repository, or repo, is a project directory where Git tracks code changes. Think of version control as a more durable form of undo: commits let you inspect earlier states, while a remote repository lets you store and share code away from your machine. Repositories also provide code for deployment workflows. section 2.3 section 2.3.1

Start with a local repository for each application:

  • Enter the Python or Node.js project directory and run `git init`. This creates a repository in that directory; the two applications have separate repos. section 2.3.1
  • Run `git status` to see whether files are untracked or changes await a commit. Use `git add` to select files, then `git commit -m "Initial commit"` to record them. section 2.3.1 section 2.3.6
  • Use `git log` to find past commits and `git show <commit-id>` to inspect the files and changes in one commit. section 2.3.5

A local repo does not automatically have a remote. For code hosted on GitHub, create a GitHub repository for each application, then connect the existing local repo with `git remote add origin https://github.com/yourusername/roadtok8s-py.git`. The name `origin` identifies that remote; afterward, `git push origin main` uploads the code. Later changes still need `git add` and `git commit`, but not another `git init` or `git remote add` for the same setup. section 2.4.2 section 2.4.3

Listing 2.31 GitHub push
git push origin main

The push command names both the destination remote (`origin`) and the branch (`main`). Run it after connecting the local repository to GitHub. section 2.4.3

A second remote for deployment

The same local project can point to a repository on a virtual machine. Add it under the name `vm` with `git remote add vm ssh://root@45.79.47.168/var/repos/roadtok8s/py.git`, replacing the IP address, then run `git push vm main`. Keeping `vm` distinct from `origin` makes the destination explicit. section 3.3.3

If a push fails, check the names before starting over: `git branch --show-current` identifies the local branch, and `git remote -v` lists configured remotes. Removing `.git` and reinitializing can offer a beginner a fresh start, but it discards the local commit history and should not be routine. Take particular care with directory-deletion commands. section 2.4.3 section 2.3.4

How Road to Kubernetes covers it

How deep it goes
Works through initialization, status, commits, remotes, and push troubleshooting; leaves Git branching beyond scope.
Examples
Uses separate Python and Node.js repositories, a GitHub remote, and a virtual-machine remote.
What it assumes
Starts with installing Git and teaches repository initialization without assuming prior Git setup.
What you can do after
Operate/configure it by initializing local repositories, recording changes, connecting remotes, and pushing application code.
How it connects
Connects repositories to version control, commits, GitHub, virtual machines, and CI/CD.

Also explained in

Compare how 10 books explain repository →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.