簡體   English   中英

從master分支鏡像GitHub頁面-master分支未更新

[英]Mirroring GitHub pages from master branch - master branch not updating

我想鏡像我的GitHub pages分支以匹配master分支,以便每當我推送到origin mastergh-pages分支也會自動同步並推送。

我遵循了有關如何執行此操作的教程,現在看來,每當我從master分支進行推送時,只有gh-pages分支會得到更新。

我刪除了本地和遠程gh-pages分支,

git branch -D gh-pages        # delete local
git push -u origin :gh-pages  # delete remote

然后嘗試從我的master分支中拉出 ,但出現以下錯誤:

> git checkout master
> git pull
> Your configuration specifies to merge with the ref 'refs/heads/gh-pages'
from the remote, but no such ref was fetched.

如果我推送 master分支,它將重新創建gh-pages遠程分支,但不會更新master分支。

在我的git配置文件中:

> git config -l
credential.helper=osxkeychain
user.name=Kyle
user.email=kyle@email.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/kylesb/range.js.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.push=+refs/heads/master:refs/heads/gh-pages
remote.origin.push=+refs/heads/master:refs/heads/gh-pages
branch.master.remote=origin
branch.master.merge=refs/heads/gh-pages

我怎樣才能解決這個問題?


更新:

我可以通過編輯.git / config文件並將其重置為以下原始內容來解決此問題:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/<username>/<repository_name>.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "gh-pages"]
    remote = origin
    merge = refs/heads/gh-pages

現在,我只需要手動推送gh-pages分支,一切都很好:

> git checkout gh-pages
> git merge master
> git push -u origin gh-pages

gh-pages被設置為嘗試與master合並的默認分支,但它不再存在。

使用git config --unset branch.master.merge取消設置master的合並分支。

首先,如果您使用的git少了版本2,請升級它,如果可以的話,請升級到版本2,每個pull.push都將所有更改的分支推送到遠程,甚至包括您不想推送的分支。


這是git v2.0發行說明,解釋了git處理推送方式(簡單vs匹配)的變化。

Git v2.0發行說明

向后兼容性說明

git push [$there]沒有說明要推送什么時,到目前為止,我們已經使用了傳統的matching語義(只要那里已經有同名的分支,您的所有分支都發送到遠程了)。 在Git 2.0中,默認值現在是simple語義,它推送:

  • 僅當當前分支設置為與該遠程分支集成時,才可以將當前分支轉移到具有相同名稱的分支; 要么

  • 如果要推送到通常不是從那里獲取的遠程站點,則僅將當前分支轉移到同名分支。

您可以使用配置變量push.default進行更改。 如果您想繼續使用matching語義,那么您可以將變量設置為matching ,例如。 閱讀文檔以了解其他可能性。


回答您的問題。

默認情況下,您可以將當前所在的分支推送到遠程。
由於您嘗試推送其他分支名稱,因此您在master分支上時不應這樣做。
簽出新的gh頁,然后推送到遠程

# start from current master
git checkout master

# Checkout teh new gh-pages branch
git checkout -b gh-pages

# do a force push instead of deleting the branch
# the force will override and prevoius commits
git push -f gh-pages

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM