Program Tip

Github : gh- 페이지를 마스터로 미러링

programtip 2020. 11. 9. 20:32
반응형

Github : gh- 페이지를 마스터로 미러링


GitHub에서 호스팅되는 jQuery 플러그인을 개발 중입니다. 여기에는 수동으로 복사하고 브랜치로 푸시하는 데모가 포함되어 있습니다 gh-pages. 변경 사항을 푸시 할 때 master자동으로 푸시 gh-pages되거나 적어도 미러링되는 설정이 필요합니다. .

나는 이미이 질문을 보았지만 이러한 요구 사항과 관련하여 내 질문에 실제로 대답하는지 확실하지 않습니다.

  1. 저는 Tower를 사용합니다. 솔루션이이 GUI에서 작동하는 한 터미널 (Mac)을 사용하여 구성을 변경해도 괜찮습니다.
  2. 내 컴퓨터의 모든 저장소가 아닌 특정 저장소에서만이 '미러링'을 원합니다.

건배


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

[remote "origin"]섹션에 다음 두 줄을 추가합니다 .git/config.

push = +refs/heads/master:refs/heads/gh-pages
push = +refs/heads/master:refs/heads/master

매번 push자동으로 마스터를 gh 페이지로 푸시합니다. 나는 이것을 jQuery Lifestream 프로젝트에 사용하고 있습니다.


denbuzze가 위에서 제안한 것을하지 마십시오 !! 푸시의 + (더하기 기호)는 비 빨리 감기 업데이트를 조용히 수락하도록합니다. 나는 이것이 매달린 커밋으로 이어져 작업을 잃어 버릴 수 없다는 것을 깨달았습니다. 더하기 기호를 제거하기 만하면 더 안전한 방법이됩니다.

push = refs/heads/master:refs/heads/gh-pages
push = refs/heads/master:refs/heads/master

이제 강제 업데이트를 수행하는 대신 경고 및 가져 오기 제안이 발생합니다.

To https://github.com/someuser/repo.git
 ! [rejected]        master -> gh-pages (fetch first)
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/someuser/repo.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.

@denbuzze@MCSDWVL 답변에 대한 추가 설명을 추가 하고 있습니다.

당신이 모두 밀어하려는 경우 mastergh-pages당신이 실행할 때마다 자동으로 git push origin, 당신은 아마 당신의 repo의 자식 설정에 Refspec을 추가 할 수 있습니다.

따라서 git-scm book 에 따르면 repo 구성 파일에 두 개의 값을 추가하여 두 개의 RefSpecs를 추가 할 수 있습니다 .push.git/config

[remote "origin"]
url = https://github.com/<github_user>/<repo_name>
      fetch = +refs/heads/*:refs/remotes/origin/*
      push = refs/heads/master:refs/heads/master
      push = refs/heads/master:refs/heads/gh-pages

그러면 다음이 발생합니다 git push origin.

  1. 로컬 master브랜치를 원격 master브랜치 푸시
  2. 로컬 master브랜치를 원격 gh-pages브랜치 푸시

기본적으로.

참고 : +사양 전에 a 사용 하면 repo에 강제로 푸시됩니다. 주의해서 사용하십시오.

refspec의 형식은 선택 사항 +이고 뒤에는이며 <src>:<dst>, 여기서는 <src>원격 측의 참조에 대한 패턴 <dst>이며 해당 참조가 로컬로 작성되는 위치입니다. +그것이 빨리 감기가 아닌 경우에도 참조를 업데이트 할 수 힘내을 알려줍니다.


개인적으로 이것을 별칭으로 감싸고 싶습니다.

alias gpogh="git checkout gh-pages && git merge master && git push origin gh-pages && git checkout -"

마스터를으로 미러링 gh-pages하고 github로 푸시 한 다음 작업 중이던 이전 분기로 다시 전환합니다.


또는 아래 cmd를 사용하면 로컬 마스터 브랜치를 gh-pages 마스터 브랜치로 푸시합니다. git push -f origin master:gh-pages


커밋 하고 마스터로 푸시 합니다 ..

다음 :

git checkout gh-pages  // -> go to gh-pages branch
git rebase master // bring gh-pages up to date with master
git push origin gh-pages // commit the changes
git checkout master // return to the master branch

업데이트 : 이제 GitHub에서 원하는 브랜치 및 디렉토리에서 페이지를 게시 할 수 있습니다.


It was much easier for me to use the gh-pages branch as master. There's nothing magical about "master"; it's just another branch name. There is something magical about gh-pages, because that's where GitHub is looking for index.html to serve your page.

Read more in my other answer on this topic.

Using gh-pages as master is also easier than subtrees, which are easier than mirroring. You could use git subtree as described here or here: if you have a directory which contains your demo, you can push that directory to the gh-branch with one command. Let's say you name the directory gh-pages to make things clear. Then after you've committed and pushed your changes to master, run this to update gh-pages:

git subtree push --prefix gh-pages origin gh-pages

The problem is if your files in gh-pages refer to files in other directories outside it. Symlinks don't work, so you'll have to copy files in the directory that serves as gh-pages.

If you use gh-pages as master, this problem won't occur.

참고URL : https://stackoverflow.com/questions/5807459/github-mirroring-gh-pages-to-master

반응형