如何在Github上发布页面?

如何在Github上发布页面?,github,Github,看起来很简单,我读了很多关于它的书,但我有一些问题要做 git add . git commit -m "documentation improvements" git push -u origin master git push -u origin gh-pages error: src refspec gh-pages does not match any. error: failed to push some refs to 'https://github.com/danielfpedr

看起来很简单,我读了很多关于它的书,但我有一些问题要做

git add .
git commit -m "documentation improvements"
git push -u origin master
git push -u origin gh-pages

error: src refspec gh-pages does not match any.
error: failed to push some refs to 'https://github.com/danielfpedro/simple-modal
.git'
我缺少什么?

您是否在存储库中设置了新的“孤立”分支?如果没有,请从存储库执行此操作:

git checkout --orphan gh-pages
并创建一些内容:

echo "Sample" > index.html
git add index.html
git commit -a -m "Sample page"
git push origin gh-pages
现在您应该可以看到您的页面了(几分钟后)。

文档可能会有所帮助。即:

1) 退出当前回购并创建新的克隆: 2) 创建gh pages分支(没有任何父级)并从工作目录和索引中删除所有内容: 3) 添加内容并推送 推送到
gh页面
分支后,您的项目页面将在
danielfpedro.github.io/simple model上可用

4) 删除克隆文件夹(
简单模式网页
)并在原始回购(
简单模式
)中拉取分支
gh页面
): 5) 就是这样,现在您还有1个分支
gh页面
。使用它提交github网页的更改:
git签出页面
git添加。
git提交-m“文档改进”
git推送-u源gh页面

更新

如果您使用的是
npm
请使用。
如果您正在使用其他工具构建站点,下面的解决方案仍然有效

旧答案

这种方法不会强制您从.gitignore文件中删除build或dist文件夹

#!/usr/bin/env bash

BUILD_DIR=build

git checkout -b _build_staging_
git add -f $BUILD_DIR
git commit -am add_build_ouput
git subtree split --prefix $BUILD_DIR -b gh-pages
git push origin gh-pages -f
git checkout -
git branch -D gh-pages _build_staging_

对于我的节点项目,我将其添加到脚本部分下的package.json文件中,并将其命名为“push”,以便我可以在终端中执行
npm run push
,将构建的输出推送到gh页面。

我仍然不明白。每次我想发布页面更改时,我都必须克隆repo并执行它?@DanielFaria用不同的directoryname克隆它怎么样。因此与当前repos目录名没有冲突。ie
git克隆https://github.com/danielfpedro/simple-modal.git 简单模式网页
@DanielFaria在初始git推送之后,然后删除文件夹
简单模式网页
,并在
简单模式
目录中拉取更改,即:
git拉取原始gh页面
-->现在更改并进一步拉取我无法获得网页和插件在同一个repo中?
cd simple-modal-webpage
git checkout --orphan gh-pages
git rm -rf . 
echo "My GitHub Page" > index.html
git add index.html
git commit -a -m "First pages commit"
git push origin gh-pages
cd ..
rm -r simple-modal-webpage
cd simple-modal
git fetch --all
git checkout -b gh-pages origin/gh-pages   #New git just use --> git checkout gh-pages
git checkout gh-pages
<made changes to documentation>
git add .
git commit -m "documentation improvements"
git push -u origin gh-pages
#!/usr/bin/env bash

BUILD_DIR=build

git checkout -b _build_staging_
git add -f $BUILD_DIR
git commit -am add_build_ouput
git subtree split --prefix $BUILD_DIR -b gh-pages
git push origin gh-pages -f
git checkout -
git branch -D gh-pages _build_staging_