Search code examples
gitdeploymentgithub-pages

Git push to gh-pages (Updates were rejected)


I have a project that is being served in a gh-pages branch in Github, from a folder called dist. I figured out how to deploy from this folder, and it went all fine until I tried to push another release.

First I commit and push to origin master. Second I add and commit the dist folder

git add dist && git commit -m "Pasta dist adicionada ao projeto"

Finally I try to push to gh-pages

git subtree push --prefix dist origin gh-pages

Here goes all log process:

samuel@debian:~/Documentos/01 - WEB/Cipher/web$ git add dist && git commit -m 

"Formulário para contato na página Contato.html"
[master 022dcf6] Formulário para contato na página Contato.html
 2 files changed, 2 insertions(+), 2 deletions(-)

samuel@debian:~/Documentos/01 - WEB/Cipher/web$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

samuel@debian:~/Documentos/01 - WEB/Cipher/web$ git push
Enter passphrase for key '/home/samuel/.ssh/cipher-deploy': 
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 452 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:samu101108/cipher-transcritor.git
   c2944ca..022dcf6  master -> master

samuel@debian:~/Documentos/01 - WEB/Cipher/web$ git add dist && git commit -m "Formulário para contato na página Contato.html"
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

samuel@debian:~/Documentos/01 - WEB/Cipher/web$ git subtree push --prefix dist origin gh-pages
git push using:  origin gh-pages
Enter passphrase for key '/home/samuel/.ssh/cipher-deploy': 
To github.com:samu101108/cipher-transcritor.git
 ! [rejected]        4d627ffb7d871a68353d427d66a00fd917fe6639 -> gh-pages (non-fast-forward)
error: failed to push some refs to '[email protected]:samu101108/cipher-transcritor.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.

So...What's wrong?


Solution

  • I got a solution! Since gh-pages branch is such a thing that could be deleted then I did it. After that I just pushed to the subtree again, hence recreating gh-pages branch and deploying with an updated version. Follows the commands I needed to accomplish it.

    $ git push origin --delete gh-pages
    $ git subtree push --prefix dist origin gh-pages