添加,提交并推送到2个远程GitHub存储库

时间:2017-03-23 10:25:32

标签: git github github-pages pelican

1。简言之

我没有找到,我如何快速添加,提交和推送更改到2个GitHub存储库,我不需要每次单独添加,提交和推送更改到2个GitHub存储库。

2。示例工作区

本地工作区:

SashaSource
    .git
    SashaSourceSubfolder1
    SashaSourceSubfolder2
    SashaOutput.github.io
        .git
        index.html
        SashaAnother.html

我有2个远程GitHub存储库:

  • SashaSource - 用于SashaSource本地目录;
  • SashaOutput.github.io - 用于SashaOutput.github.io本地目录,我的GitHub Pages网站的位置。

我使用Pelican static site generator。我在SashaSourceSubfolder1SashaSourceSubfolder2 folder进行了更改→我进行了构建(使用makefabric工具或pelican content命令)→我在{{ 1}}文件夹。 (我设置了Pelican,SashaOutput.github.io文件夹不会更改,如果我进行构建

现在我想将我的更改推送到SashaOutput.github.io/.gitSashaSource远程存储库。

3。实际行为

我需要运行

SashaOutput.github.io
git add . && git commit -m "Example commit description" && git push 存储库中的

比我需要向SashaSource存储库运行相同的命令。

4。预期的行为

我在终端中打印任何命令→git push更改为SashaOutput.github.ioSashaSource远程存储库都具有相同的提交描述,该用户不需要每次运行相同的命令2次。 / p>

5。没帮忙

  1. 我读到了git submodules,但我没有找到,我怎么能解决我的问题。
  2. 我发现,如何推动变革to 2 remote repositories。我设置SashaOutput.github.iogit remote→我得到输出:

    git add . && git commit -m "Example commit description"

    我的更改推送到1个远程存储库。我想,我需要在推送之前添加并提交对D:\SashaSource\>git push all To https://github.com/Kristinita/SashaOutput.github.io.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/Kristinita/SashaOutput.github.io.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull …') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 770 bytes | 0 bytes/s, done. Total 4 (delta 3), reused 0 (delta 0) remote: Resolving deltas: 100% (3/3), completed with 3 local objects. To https://github.com/Kristinita/SashaSource dc36727..3e5d63b master -> master 的更改,但我找不到,我怎么做。

  3. 我读了another Stack Overflow questions关于推送到2个或更多的存储库,但我没有找到,用户如何添加和提交对2个存储库的更改。< / p>

  4. 我不明白,我怎样才能在Windows中编写预期行为的脚本。提交描述 - 是一个变量,如何在脚本中使用它?

  5. 6。不提供

    1. 我的输出SashaOutput.github.io需要单独的存储库,因为GitHub Pages不支持Pelican的源,需要在存储库的根目录中输出目录。请不要为我的网站使用1个远程GitHub存储库,而不是2。
    2. 请不要提供,我需要使用Jekyll。
    3. 7。环境

      操作系统和版本:
      Windows 10企业版LTSB 64位EN
      GIT中:
      版本2.12.0.windows.1

1 个答案:

答案 0 :(得分:0)

Windows用户解决方案。

1。预期的行为

第3节中的脚本添加,提交并推送对远程源存储库(SashaSource有问题)的更改,然后添加,提交并将更改推送到远程输出存储库(SashaOutput.github.io)。对于两个存储库的提交消息,将设置变量(%SASHAMESSAGE%作为答案)。

2。设置提交消息

在首选终端中打印:

SET SASHAMESSAGE=[Test] Sasha Princess of the Universe!
  • SASHAMESSAGE - 提交消息的变量;
  • [Test] Sasha Princess of the Universe! - 示例提交消息。

3。批处理文件

创建扩展名为bat的文件,例如GitPush2Repositories.bat

git add .
git commit -m "%SASHAMESSAGE%"
git push
cd SashaOutput.github.io
git add .
git commit -m "%SASHAMESSAGE%"
git push
  • SashaOutput.github.io - 您的输出文件夹。

4。运行批处理

在源文件夹中打开终端(问题中为SashaSource)→在终端中打印:

"D:\SashaBatch\GitPush2Repositories.bat"
  • D:\SashaBatch\GitPush2Repositories.bat - bat文件的路径。

你必须得到预期的行为。

5。额外链接

相关问题