<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>github on Eric Jin</title>
    <link>https://ericjin.com/blog/tags/github/</link>
    <description>Recent content in github on Eric Jin</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 04 Apr 2023 20:01:23 +0800</lastBuildDate>
    <atom:link href="https://ericjin.com/blog/tags/github/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>相互同步 VPS 和 GitHub 上的 git 仓库</title>
      <link>https://ericjin.com/blog/%E7%9B%B8%E4%BA%92%E5%90%8C%E6%AD%A5-VPS-%E5%92%8C-GitHub-%E4%B8%8A%E7%9A%84-git-%E4%BB%93%E5%BA%93/</link>
      <pubDate>Tue, 04 Apr 2023 20:01:23 +0800</pubDate>
      <guid>https://ericjin.com/blog/%E7%9B%B8%E4%BA%92%E5%90%8C%E6%AD%A5-VPS-%E5%92%8C-GitHub-%E4%B8%8A%E7%9A%84-git-%E4%BB%93%E5%BA%93/</guid>
      <description>背景 由于公司或者某些地方对 GitHub 的网络非常的不友好，所以我希望这时候把代码直接推送到我的服务器上，由服务器同步到 GitHub 上去。&#xA;而家里的网络我会直接推送到 GitHub，所以这个时候也需要 GitHub 能把代码同步到服务器上，便于其他客户端从服务器获取到最新的代码。&#xA;步骤 1. 在服务器上创建空仓库 在服务器上创建一个新的空仓库作为中转站，该仓库将不储存代码，只保存提交记录（即git log）。例如，你可以使用以下命令在中转服务器上创建一个新的仓库：&#xA;mkdir myrepo.git cd myrepo.git git init --bare 2. 在中转服务器上添加 Git hook 在中转服务器上，创建一个名为 post-receive 的 Git hook，并添加以下脚本：&#xA;#!/bin/bash while read oldrev newrev refname do # 只在主分支上的提交才触发 if [[ $refname = &amp;#34;refs/heads/main&amp;#34; ]]; then # 将代码推送到 GitHub git push origin main fi done post-receive hook 将会在有新的代码提交时被触发，并自动将代码推送到 GitHub 的特定仓库中。&#xA;3. 为 post-receive 文件添加可执行权限 保存并退出 post-receive 文件。然后，为 post-receive 文件添加可执行权限。</description>
    </item>
  </channel>
</rss>
