本地 Git 远程仓库

Hacker News Top 工具

摘要

关于如何使用裸仓库为个人项目设置本地 Git 远程仓库的教程,支持离线友好的推/拉工作流。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/05/29 16:19

# 本地 Git 远程仓库 — Alexander Cobleigh 来源:https://cblgh.org/posts/local-git-remotes/ 在开发 [cani](https://cblgh.org/cani) 的过程中,我同时使用了多种 Git 远程仓库。其中一个远程仓库托管在我家里的服务器上。以下是我的设置方法。 假设服务器上有一个名为 `cani` 的项目文件夹。该文件夹包含代码和一个 `.git/` 目录: ``` /home/user/projects/cani ``` 我们可以利用上述文件夹来克隆一个**裸仓库**(可作为远程仓库使用,且不会引发奇怪的冲突): ``` cd /home/user/bares git clone --bare /home/user/projects/cani # 创建了 /home/user/bares/cani.git ``` 将这个裸仓库添加为远程仓库以便进行推送和拉取,可以有几种不同的方式。以下是在同一台机器上设置远程仓库的方法: ``` git remote add local /home/user/bares/cani.git ``` 以下是在另一台机器上推送时设置远程仓库的方法: ``` git remote add local ssh://USER@MACHINE:/home/user/bares/cani.git ``` 我们可以将分支 `main` 关联为远程仓库 `local` 的默认分支: ``` git remote set-branches local main ``` 现在,我们可以向 `local` 远程仓库推送了! ``` # 无任何配置 git push ssh://USER@MACHINE:/home/user/bares/cani.git # 如果已按上述方式配置了 ssh://USER@ 的远程仓库 git push local ``` 从已配置的远程仓库拉取: ``` # 无默认分支 git pull local main # 已设置默认分支 `main` git pull local ``` 值得一提的是,`ssh://USER@MACHINE` 语法可以替换为你本地已配置的任何 SSH 设置。 总之,我非常喜欢使用本地远程仓库,尤其是在处理在线率较低的异地远程仓库时。设置本地远程仓库后,使用一个可能并不总是可用的远程仓库变得轻松了许多。就我个人而言,那个异地远程仓库是一个小型社区服务器,正遭受大企业爬虫的猛烈攻击。现在,我两者兼得:一个可以无延迟推送的本地远程仓库,以及一个由在线社区的朋友托管的异地副本。值得注意的是,这里没有大科技公司的参与!

相似文章

@itsclelia: I have one big problem with agentic engineering: I want agents to operate autonomously, but I also want granular, rever…

X AI KOLs Timeline

I have one big problem with agentic engineering: I want agents to operate autonomously, but I also want granular, reversible control over every change they make. I could solve this by committing every intermediate step to Git, but that would completely pollute my repo history. So I built 𝗮𝗴𝗴𝗶𝘁: a Git-like CLI for local and remote (S3-backed) agent artifact storage, written in Rust . With aggit, my agents can stash intermediate work, create branches safely, restore previous states, and back

grasp:一种简单的去中心化 Git 协议

Lobsters Hottest

Grasp 推出了一种去中心化 Git 协议,并附带名为 nak 的 CLI 工具,支持在无账户、仅签名消息的情况下,在自托管服务器间协作,同时保持完全互操作性。