Git 中文文档 Git 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • 起步

    • 1.1 关于版本控制
    • 1.2 git 简史
    • 1.3 git 是什么
    • 1.4 命令行
    • 1.5 安装 git
    • 1.6 初次运行git前的配置
    • 1.7 获取帮助
    • 1.8 起步 - 总结
  • git 基础

  • git 分支

  • 服务器上的 git

  • 分布式 git

  • github

  • git 工具

  • 自定义 git

  • git 与其他系统

  • git 内部原理

Soft Serve


Build Status

A tasty, self-hostable Git server for the command line. 🍦

Easy to navigate TUI available over SSH
Clone repos over SSH, HTTP, or Git protocol
Manage repos with SSH
Create repos on demand with SSH or git push
Browse repos, files and commits with SSH-accessible
Print files over SSH with or without syntax highlighting and line numbers
Easy access control with SSH
Allow/disallow anonymous access
Add collaborators with SSH public keys
Repos can be public or private

Where can I see it?


Just run ssh git.charm.sh for an example. You can also try some of the following commands:

  1. ``` shell
  2. # Jump directly to a repo in the TUI
  3. ssh git.charm.sh -t soft-serve

  4. # Print out a directory tree for a repo
  5. ssh git.charm.sh repo tree soft-serve

  6. # Print a specific file
  7. ssh git.charm.sh repo blob soft-serve cmd/soft/root.go

  8. # Print a file with syntax highlighting and line numbers
  9. ssh git.charm.sh repo blob soft-serve cmd/soft/root.go -c -l
  10. ```

Installation


Soft Serve is a single binary called soft. You can get it from a package manager:

  1. ``` shell
  2. # macOS or Linux
  3. brew tap charmbracelet/tap && brew install charmbracelet/tap/soft-serve

  4. # Arch Linux
  5. pacman -S soft-serve

  6. # Nix
  7. nix-env -iA nixpkgs.soft-serve

  8. # Debian/Ubuntu
  9. sudo mkdir -p /etc/apt/keyrings
  10. curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
  11. echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
  12. sudo apt update && sudo apt install soft-serve

  13. # Fedora/RHEL
  14. echo '[charm]
  15. name=Charm
  16. baseurl=https://repo.charm.sh/yum/
  17. enabled=1
  18. gpgcheck=1
  19. gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
  20. sudo yum install soft-serve
  21. ```

You can also download a binary from the releases page. Packages are available in Alpine, Debian, and RPM formats. Binaries are available for Linux, macOS, and Windows.

Or just install it with go :

  1. ``` shell
  2. go install github.com/charmbracelet/soft-serve/cmd/soft@latest
  3. ```

A Docker image is also available.

Setting up a server


Make sure git is installed, then run soft serve. That’s it.

This will create a data directory that will store all the repos, ssh keys, and database.

To change the default data path use SOFT_SERVE_DATA_PATH environment variable.

  1. ``` shell
  2. SOFT_SERVE_DATA_PATH=/var/lib/soft-serve soft serve
  3. ```

When you run Soft Serve for the first time, make sure you have the SOFT_SERVE_INITIAL_ADMIN_KEYS environment variable is set to your ssh authorized key. Any added key to this variable will be treated as admin with full privileges.

Using this environment variable, Soft Serve will create a new admin user that has full privileges. You can rename and change the user settings later.

Server Settings


Once you start the server for the first time, the settings will be in config.yaml under your data directory. The default config.yaml is self-explanatory and will look like this:

  1. ``` yaml
  2. # Soft Serve Server configurations

  3. # The name of the server.
  4. # This is the name that will be displayed in the UI.
  5. name: "Soft Serve"

  6. # Log format to use. Valid values are "json", "logfmt", and "text".
  7. log_format: "text"

  8. # The SSH server configuration.
  9. ssh:
  10.   # The address on which the SSH server will listen.
  11.   listen_addr: ":23231"

  12.   # The public URL of the SSH server.
  13.   # This is the address that will be used to clone repositories.
  14.   public_url: "ssh://localhost:23231"

  15.   # The path to the SSH server's private key.
  16.   key_path: "ssh/soft_serve_host"

  17.   # The path to the SSH server's client private key.
  18.   # This key will be used to authenticate the server to make git requests to
  19.   # ssh remotes.
  20.   client_key_path: "ssh/soft_serve_client"

  21.   # The maximum number of seconds a connection can take.
  22.   # A value of 0 means no timeout.
  23.   max_timeout: 0

  24.   # The number of seconds a connection can be idle before it is closed.
  25.   idle_timeout: 120

  26. # The Git daemon configuration.
  27. git:
  28.   # The address on which the Git daemon will listen.
  29.   listen_addr: ":9418"

  30.   # The maximum number of seconds a connection can take.
  31.   # A value of 0 means no timeout.
  32.   max_timeout: 0

  33.   # The number of seconds a connection can be idle before it is closed.
  34.   idle_timeout: 3

  35.   # The maximum number of concurrent connections.
  36.   max_connections: 32

  37. # The HTTP server configuration.
  38. http:
  39.   # The address on which the HTTP server will listen.
  40.   listen_addr: ":23232"

  41.   # The path to the TLS private key.
  42.   tls_key_path: ""

  43.   # The path to the TLS certificate.
  44.   tls_cert_path: ""

  45.   # The public URL of the HTTP server.
  46.   # This is the address that will be used to clone repositories.
  47.   # Make sure to use https:// if you are using TLS.
  48.   public_url: "http://localhost:23232"

  49. # The stats server configuration.
  50. stats:
  51.   # The address on which the stats server will listen.
  52.   listen_addr: ":23233"

  53. # Additional admin keys.
  54. #initial_admin_keys:
  55. #  - "ssh-rsa AAAAB3NzaC1yc2..."

  56. ```

You can also use environment variables, to override these settings. All server settings environment variables start with SOFT_SERVE_ followed by the setting name all in uppercase. Here are some examples:

SOFT_SERVE_NAME : The name of the server that will appear in the TUI
SOFT_SERVE_SSH_LISTEN_ADDR : SSH listen address
SOFT_SERVE_SSH_KEY_PATH : SSH host key-pair path
SOFT_SERVE_HTTP_LISTEN_ADDR : HTTP listen address
SOFT_SERVE_HTTP_PUBLIC_URL : HTTP public URL used for cloning
SOFT_SERVE_GIT_MAX_CONNECTIONS : The number of simultaneous connections to git daemon

Configuration


Configuring Soft Serve is simple and straightforward. Use the SSH command-line interface to manage access settings, users, and repos.

Try ssh localhost -i ~/.ssh/id_ed25519 -p 23231 help for more info. Make sure you use your key here.

For ease of use, instead of specifying the key, port, and hostname every time you SSH into Soft Serve, add your own Soft Serve instance entry to your SSH config. For instance, to use ssh soft instead of typing `ssh localhost -i /.ssh/id_ed25519 -p 23231, we can define a soft entry in our SSH config file /.ssh/config`.

  1. ``` sh
  2. Host soft
  3.   HostName localhost
  4.   Port 23231
  5.   IdentityFile ~/.ssh/id_ed25519

  6. ```

Now, we can do ssh soft to SSH into Soft Serve. Since git is also aware of this config, you can use soft as the hostname for your clone commands.

  1. ``` shell
  2. git clone ssh://soft/dotfiles
  3. # make changes
  4. # add & commit
  5. git push origin main
  6. ```

NoteThe -i part will be omitted in the examples below for brevity. You can add your server settings to your sshconfig for quicker access.


Access Levels


Soft Serve offers a simple access control. There are four access levels, no-access, read-only, read-write, and admin-access.

admin-access has full control of the server and can make changes to users and repos.

read-write access gets full control of repos.

read-only can read public repos.

no-access denies access to all repos.

Authentication


Everything that needs authentication is done using SSH. Make sure you have added an entry for your Soft Serve instance in your ~/.ssh/config file.

By default, Soft Serve gives ready-only permission to anonymous connections to any of the above protocols. This is controlled by two settings anon-access and allow-keyless.

anon-access : Defines the access level for anonymous users. Available options are no-access, read-only, read-write, and admin-access. Default is read-only.
allow-keyless : Whether to allow connections that doesn't use keys to pass. Setting this to false would disable access to SSH keyboard-interactive, HTTP, and Git protocol connections. Default is true.

  1. ``` shell
  2. $ ssh -p 23231 localhost settings
  3. Manage server settings

  4. Usage:
  5.   ssh -p 23231 localhost settings [command]

  6. Available Commands:
  7.   allow-keyless Set or get allow keyless access to repositories
  8.   anon-access   Set or get the default access level for anonymous users

  9. Flags:
  10.   -h, --help   help for settings

  11. Use "ssh -p 23231 localhost settings [command] --help" for more information about a command.
  12. ```

NoteThese settings can only be changed by admins.


When allow-keyless is disabled, connections that don't use SSH Public Key authentication will get denied. This means cloning repos over HTTP(s) or git:// will get denied.

Meanwhile, anon-access controls the access level granted to connections that use SSH Public Key authentication but are not registered users. The default setting for this is read-only. This will grant anonymous connections that use SSH Public Key authentication read-only access to public repos.

anon-access is also used in combination with allow-keyless to determine the access level for HTTP(s) and git:// clone requests.

Authorization


Admins can manage users and their keys using the user command. Once a user is created and has access to the server, they can manage their own keys and settings.

To create a new user simply use user create :

  1. ``` shell
  2. # Create a new user
  3. ssh -p 23231 localhost user create beatrice

  4. # Add user keys
  5. ssh -p 23231 localhost user add-pubkey beatrice ssh-rsa AAAAB3Nz...
  6. ssh -p 23231 localhost user add-pubkey beatrice ssh-ed25519 AAAA...

  7. # Create another user with public key
  8. ssh -p 23231 localhost user create frankie '-k "ssh-ed25519 AAAATzN..."'

  9. # Need help?
  10. ssh -p 23231 localhost user help
  11. ```

Once a user is created, they get read-only access to public repositories. They can also create new repositories on the server.

Users can manage their keys using the pubkey command:

  1. ``` shell
  2. # List user keys
  3. ssh -p 23231 localhost pubkey list

  4. # Add key
  5. ssh -p 23231 localhost pubkey add ssh-ed25519 AAAA...

  6. # Wanna change your username?
  7. ssh -p 23231 localhost set-username yolo

  8. # To display user info
  9. ssh -p 23231 localhost info
  10. ```

Repositories


You can manage repositories using the repo command.

  1. ``` shell
  2. # Run repo help
  3. $ ssh -p 23231 localhost repo help
  4. Manage repositories

  5. Usage:
  6.   ssh -p 23231 localhost repo [command]

  7. Aliases:
  8.   repo, repos, repository, repositories

  9. Available Commands:
  10.   blob         Print out the contents of file at path
  11.   branch       Manage repository branches
  12.   collab       Manage collaborators
  13.   create       Create a new repository
  14.   delete       Delete a repository
  15.   description  Set or get the description for a repository
  16.   hide         Hide or unhide a repository
  17.   import       Import a new repository from remote
  18.   info         Get information about a repository
  19.   is-mirror    Whether a repository is a mirror
  20.   list         List repositories
  21.   private      Set or get a repository private property
  22.   project-name Set or get the project name for a repository
  23.   rename       Rename an existing repository
  24.   tag          Manage repository tags
  25.   tree         Print repository tree at path

  26. Flags:
  27.   -h, --help   help for repo

  28. Use "ssh -p 23231 localhost repo [command] --help" for more information about a command.
  29. ```

To use any of the above repo commands, a user must be a collaborator in the repository. More on this below.

Creating Repositories


To create a repository, first make sure you are a registered user. Use the repo create <repo> command to create a new repository:

  1. ``` shell
  2. # Create a new repository
  3. ssh -p 23231 localhost repo create icecream

  4. # Create a repo with description
  5. ssh -p 23231 localhost repo create icecream '-d "This is an Ice Cream description"'

  6. # ... and project name
  7. ssh -p 23231 localhost repo create icecream '-d "This is an Ice Cream description"' '-n "Ice Cream"'

  8. # I need my repository private!
  9. ssh -p 23231 localhost repo create icecream -p '-d "This is an Ice Cream description"' '-n "Ice Cream"'

  10. # Help?
  11. ssh -p 23231 localhost repo create -h
  12. ```

Or you can add your Soft Serve server as a remote to any existing repo, given you have write access, and push to remote:

  1. ``` sh
  2. git remote add origin ssh://localhost:23231/icecream

  3. ```

After you’ve added the remote just go ahead and push. If the repo doesn’t exist on the server it’ll be created.

  1. ``` sh
  2. git push origin main

  3. ```

Repositories can be nested too:

  1. ``` shell
  2. # Create a new nested repository
  3. ssh -p 23231 localhost repo create charmbracelet/icecream

  4. # Or ...
  5. git remote add charm ssh://localhost:23231/charmbracelet/icecream
  6. git push charm main
  7. ```

Deleting Repositories


You can delete repositories using the repo delete <repo> command.

  1. ``` shell
  2. ssh -p 23231 localhost repo delete icecream
  3. ```

Renaming Repositories


Use the repo rename <old> <new> command to rename existing repositories.

  1. ``` shell
  2. ssh -p 23231 localhost repo rename icecream vanilla
  3. ```

Repository Collaborators


Sometimes you want to restrict write access to certain repositories. This can be achieved by adding a collaborator to your repository.

Use the repo collab <command> <repo> command to manage repo collaborators.

  1. ``` shell
  2. # Add collaborator to soft-serve
  3. ssh -p 23231 localhost repo collab add soft-serve frankie

  4. # Remove collaborator
  5. ssh -p 23231 localhost repo collab remove soft-serve beatrice

  6. # List collaborators
  7. ssh -p 23231 localhost repo collab list soft-serve
  8. ```

Repository metadata


You can also change the repo's description, project name, whether it's private, etc using the repo <command> command.

  1. ``` shell
  2. # Set description for repo
  3. ssh -p 23231 localhost repo description icecream "This is a new description"

  4. # Hide repo from listing
  5. ssh -p 23231 localhost repo hidden icecream true

  6. # List repository info (branches, tags, description, etc)
  7. ssh -p 23231 localhost repo icecream info
  8. ```

To make a repository private, use repo private <repo> [true|false]. Private repos can only be accessed by admins and collaborators.

  1. ``` shell
  2. ssh -p 23231 localhost repo icecream private true
  3. ```

Repository Branches & Tags


Use repo branch and repo tag to list, and delete branches or tags. You can also use repo branch default to set or get the repository default branch.

Repository Tree


To print a file tree for the project, just use the repo tree command along with the repo name as the SSH command to your Soft Serve server:

  1. ``` shell
  2. ssh -p 23231 localhost repo tree soft-serve
  3. ```

You can also specify the sub-path and a specific reference or branch.

  1. ``` shell
  2. ssh -p 23231 localhost repo tree soft-serve server/config
  3. ssh -p 23231 localhost repo tree soft-serve main server/config
  4. ```

From there, you can print individual files using the repo blob command:

  1. ``` shell
  2. ssh -p 23231 localhost repo blob soft-serve cmd/soft/root.go
  3. ```

You can add the -c flag to enable syntax coloring and -l to print line numbers:

  1. ``` shell
  2. ssh -p 23231 localhost repo blob soft-serve cmd/soft/root.go -c -l

  3. ```

Use --raw to print raw file contents. This is
Last Updated: 2023-09-03 19:17:54