You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To https://{TOKEN}@github.com/owner/repo.git
! [rejected] gh-pages -> gh-pages (fetch first)
error: failed to push some refs to 'https://{TOKEN}@github.com/owner/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.
Some possible fixes:
Add --force to the push command (cheap, well understood, but rebase still fails so the git history on gh-pages gets real long).
If remote name starts with 'http', run git remote set-url origin {REMOTE-URL} before the rebase. This should allow the git commands that can't hand a URL as a remote to function properly. This doesn't address the fact that the rebase fails.
Go for a simpler git model that will always destroy the gh-pages branch for real. E.g., check if branch gh-pages exists (git branch -r). If so, delete it locally (git branch -D gh-pages) and remotely (git push origin :gh-pages). This could replace the try_rebase call in ghp_import and we could continue with run_import knowing the gh-pages branch is fresh.
Maybe I'm missing a better option, if so happy to do some more investigation if y'all have suggestions.
@pjbull thanks for doing all the work on this. I agree using force is probably the best way to address this. However, as I understand it, this is not a problem for all users (perhaps only for those doing automated updates from CI servers), so the use of force should be an option. In fact, in all the examples you point to, the user is explicitly including the --force flag in their script.
That being the case, my inclination is to add a --force flag (off by default) to the gh-deploy command which then gets passed along. Then you (and others) can simply include that flag in your automation script: mkdocs gh-deploy --force ....
The only hesitation I have is that we might want to explore merging recent updates to ghp_import which are missing from our vendored copy. If we are going to do that, I think that should happen first. And perhaps we should offer to pass our local modifications to ghp_import back upstream. Maybe that project could then be better at both being a lib and a command line tool. If so, we would no longer need to vendor it, which makes for simpler maintenance.
By the way, a possible workaround might be to use git-subtree instead of our gh-deploy command. It can copy (and preserve) the history of a subdirectory to a separate branch. It will only copy the commits which effected the specified sub-directory. Additionally, any commits which included changes in both the specified subdirectory and other parts of your source only include the changes to the subdirectory. I did a full write-up on how to use it with GitHub Pages a while back.
Just be aware that if you have been using our gh-deploy command, you will need to delete the existing gh-pages branch both locally and remotely before using git-subtree the first time.
Personally, I prefer the approach of git-subtree and would like to use it under-the-hood for gh-deploy. However, it requires installation of a non-standard git extension which does not have a clean install path on all systems. The existing solution is just easier to get new users up-to-speed on.
👌 I'll start with --force as an option, since that seems easiest to implement and for existing users. I'll take a look at pulling the upstream changes to the vendored copy.
Just to get a couple more notes about other options in one place:
Looks like subtree is now in git, so no need for a separate install (though we would take a git>=1.7.11 dependency).
Another option, which seems pretty clean comes from this comment:
Keep site in .gitignore
On deploy, git clone gh-pages into the site directory
Clean and build the site
cd into the directory, git add, git commit and git push
@pjbull I just created a PR (#1023) which adds a --force flag. Does this resolve your problem? As far I can tell, it is working, but I wasn't having a problem which needed the force to begin with.
Not sure what objects are messed up, because I see the git pull --rebase doesn't actual merges anything. --force flag will definitely not work for those whose history is not over-writable. 🤔
Each gh-deploy command creates another commit on the localgh-pages branch. If for some reason the local gh-pages branch and the remove have been diverged (someone else pushed docs, for example), you won't be able to push without force.
to fix it:
git branch -D gh-pages
git checkout -t upstream/gh-pages (change upstream to your actual remote)
git checkout master
Than your local gh-pages and the remote one are the same. Now you can gh-deploy that will create another commit on top of the current commit and will work without force.
The actual "bug" in here is that gh-deploy doesn't pull the latest from the remote.
Reacted by Martin Bonnin, Hadrien Mary, Steffen Schroeder, Matthew Johnson, VB, John Boyer and Alexander Kain
Activity
pjbull commentedon Jun 26, 2016
Hm. There's a bit of a 🐰 hole here. For context, this is using the token approach from #632 to deploy updates using a CI server.
Looks like the root cause is in these lines of code.
Here's where I see the problem:
mkdocs gh-deploy --clean --remote-name https://{TOKEN}@github.com/owner/repo.gitgit rev-listwith a URL as the remote, we would normally see the errorfatal: Invalid object name 'https'.try_rebasereturns True on line 76 ifrev-listfails, so we just never do the rebase.git pushwe see an error (which before Error on failure to git push as part of gh-deploy #967 would fail silently):Some possible fixes:
--forceto the push command (cheap, well understood, but rebase still fails so the git history on gh-pages gets real long).git remote set-url origin {REMOTE-URL}before the rebase. This should allow the git commands that can't hand a URL as a remote to function properly. This doesn't address the fact that the rebase fails.gh-pagesexists (git branch -r). If so, delete it locally (git branch -D gh-pages) and remotely (git push origin :gh-pages). This could replace thetry_rebasecall inghp_importand we could continue withrun_importknowing the gh-pages branch is fresh.Maybe I'm missing a better option, if so happy to do some more investigation if y'all have suggestions.
pjbull commentedon Jun 26, 2016
FWIW, it seems that for other similar tasks (e.g., using Sphinx or Pelican to push to gh-pages) people often include a force push after
ghp-import:waylan commentedon Jun 26, 2016
@pjbull thanks for doing all the work on this. I agree using force is probably the best way to address this. However, as I understand it, this is not a problem for all users (perhaps only for those doing automated updates from CI servers), so the use of force should be an option. In fact, in all the examples you point to, the user is explicitly including the
--forceflag in their script.That being the case, my inclination is to add a
--forceflag (off by default) to thegh-deploycommand which then gets passed along. Then you (and others) can simply include that flag in your automation script:mkdocs gh-deploy --force ....The only hesitation I have is that we might want to explore merging recent updates to ghp_import which are missing from our vendored copy. If we are going to do that, I think that should happen first. And perhaps we should offer to pass our local modifications to ghp_import back upstream. Maybe that project could then be better at both being a lib and a command line tool. If so, we would no longer need to vendor it, which makes for simpler maintenance.
waylan commentedon Jun 26, 2016
By the way, a possible workaround might be to use git-subtree instead of our
gh-deploycommand. It can copy (and preserve) the history of a subdirectory to a separate branch. It will only copy the commits which effected the specified sub-directory. Additionally, any commits which included changes in both the specified subdirectory and other parts of your source only include the changes to the subdirectory. I did a full write-up on how to use it with GitHub Pages a while back.Just be aware that if you have been using our
gh-deploycommand, you will need to delete the existinggh-pagesbranch both locally and remotely before using git-subtree the first time.Personally, I prefer the approach of git-subtree and would like to use it under-the-hood for
gh-deploy. However, it requires installation of a non-standard git extension which does not have a clean install path on all systems. The existing solution is just easier to get new users up-to-speed on.pjbull commentedon Jun 27, 2016
👌 I'll start with
--forceas an option, since that seems easiest to implement and for existing users. I'll take a look at pulling the upstream changes to the vendored copy.Just to get a couple more notes about other options in one place:
Looks like
subtreeis now in git, so no need for a separate install (though we would take a git>=1.7.11 dependency).Another option, which seems pretty clean comes from this comment:
.gitignoregit clonegh-pages into the site directorygit add,git commitandgit pushwaylan commentedon Jun 27, 2016
Yes, I know, but as that page states:
Which is the same as not being included in git on most systems. So, yes, a separate install is still necessary.
Add --force flag to gh-deploy command.
waylan commentedon Aug 11, 2016
@pjbull I just created a PR (#1023) which adds a
--forceflag. Does this resolve your problem? As far I can tell, it is working, but I wasn't having a problem which needed the force to begin with.Add --force flag to gh-deploy command.
pjbull commentedon Aug 11, 2016
Tested and it works beautifully. Thanks @waylan! Confirmed repro w/o
--forceflag and then success with--force.(Also, was hoping to get a PR to you all, but it was a busy summer... I'll pick off another issue to help out on.)
waylan commentedon Aug 11, 2016
Thanks for the quick feedback. Once the CI tests finish, I'll merge the PR.
gregglind commentedon Aug 17, 2016
(what is the 'while we wait for 0.16' solution here?)
waylan commentedon Aug 17, 2016
I don't know that there is one. However, I expect that 0.16 will be released very soon (see #907).
azbarcea commentedon Aug 26, 2018
The way it seems to work for me, without
--forceflag is:Not sure what
objectsare messed up, because I see thegit pull --rebasedoesn't actual merges anything.--forceflag will definitely not work for those whose history is not over-writable. 🤔e-orz commentedon Apr 10, 2019
Each
gh-deploycommand creates another commit on the localgh-pagesbranch. If for some reason the local gh-pages branch and the remove have been diverged (someone else pushed docs, for example), you won't be able to push without force.to fix it:
Than your local gh-pages and the remote one are the same. Now you can
gh-deploythat will create another commit on top of the current commit and will work without force.The actual "bug" in here is that
gh-deploydoesn't pull the latest from the remote.force gh-deploy push
Force push docs
Add force flag - see mkdocs/mkdocs#973
Add CI workflow to publish docs using mkdocs (#105)
fix: workaround gh-pages issue
Force docs deploy (#9)