Skip to content

Instantly share code, notes, and snippets.

@mandiwise
Last active September 28, 2024 09:43
Show Gist options
  • Save mandiwise/44d1edce18f2ffb14f63 to your computer and use it in GitHub Desktop.
Save mandiwise/44d1edce18f2ffb14f63 to your computer and use it in GitHub Desktop.
Keep gh-pages up to date with a master branch
// Reference: http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/
$ git add .
$ git status // to see what changes are going to be commited
$ git commit -m 'Some descriptive commit message'
$ git push origin master
$ git checkout gh-pages // go to the 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
@PalashBansal
Copy link

Thanks for this code snippet!

Here is an alias to run after git push origin master. Place this in your .gitconfig, mine is located in ~/Users/danielstepanov/.gitconfig

[alias]
	sync-ghpages = !git checkout gh-pages && git rebase master && git push origin gh-pages && git checkout master

Once added, you can run git sync-ghpages and it will automatically do the second half of the above code. I'm extremely lazy.

thanks a lot :)

Copy link

ghost commented Feb 15, 2020

It worked! Thanks a lot.

@xavierchia
Copy link

Amazing.

@PalashBansal
Copy link

I looked into one of my projects again having gh-pages. Noticed that, now github provides direct publishing of master branch. index.htm should be there in master branch root folder. No more gh-pages needed.
For eg.- in repo https://github.com/PalashBansal/Collision
http://palashbansal.github.io/Collision gets updated on any change commited in master branch. gh-pages is left unused.
To set this-
Go to your repo settings, under GitHub Pages > Change Source under - Your GitHub Pages site is currently being built from the master branch. to master branch. You can even select the folder in your root folder- master branch / docs folder

@mrangta
Copy link

mrangta commented Feb 28, 2020

You are a life saver !!! Thanks a lot :)

@symoon94
Copy link

symoon94 commented May 14, 2020

You guys don't need to push the whole updates to gh-pages and even to master for updating your site. If you want to see updates on your git page, then just wait for a few minutes after "npm run deploy" on the master branch. Then, it'll be updated as you expect.

@effrenatus
Copy link

Still useful. Thanks!

@lillapulay
Copy link

Thank you very much!

@sthakur-dotnet
Copy link

Charm

@S-Philp
Copy link

S-Philp commented Nov 25, 2020

You guys don't need to push the whole updates to gh-pages and even to master for updating your site. If you want to see updates on your git page, then just wait for a few minutes after "npm run deploy" on the master branch. Then, it'll be updated as you expect.

This worked for me!!!! Thank you!!!!

@chimepalden
Copy link

@PalashBansal, I published my page using docs folder in the master branch. I made some changes and pushed it successfully in my repository but the page is not updated. Any info on how to solve this problem?

@PalashBansal
Copy link

@PalashBansal, I published my page using docs folder in the master branch. I made some changes and pushed it successfully in my repository but the page is not updated. Any info on how to solve this problem?

@chimepalden You need to wait for a while(around a minute to have change reflected), if still not working, I can help better by looking into reporsitory. Please share if it's not private.
If already solved, please let us know the issue and how it got resolved.
Thanks :)

@ukaemma2
Copy link

ukaemma2 commented Mar 9, 2021

// Reference: http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/

$ git add .
$ git status // to see what changes are going to be commited
$ git commit -m 'Some descriptive commit message'
$ git push origin master

$ git checkout gh-pages // go to the 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

i did this was able to push to gh-pages but the new updates is not relecting.

what else can i do here?

@EvroHQ
Copy link

EvroHQ commented Apr 9, 2021

Hi there, why i've this one ?

git push origin gh-pages
To https://github.com/EvroHQ/MVMT
! [rejected] gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/EvroHQ/MVMT'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@abdelghanyMh
Copy link

abdelghanyMh commented Jun 19, 2021

@EvroHQ
I'm having the same issue, Did you fix it?

@psomdeb25
Copy link

psomdeb25 commented Jul 21, 2021

I suggest after Line 9 of OP:
git rebase --continue

before writing
git push origin gh-pages

@devseme
Copy link

devseme commented Jul 23, 2021

thank you!

@kurt-krueckeberg
Copy link

Thanks!

@akram3598786
Copy link

Thanks a lot

@9grampanter
Copy link

Amazing 🥳 🎉

@hmbashar
Copy link

Thank you.
It's working fine.

@tringuyen1086
Copy link

You guys don't need to push the whole updates to gh-pages and even to master for updating your site. If you want to see updates on your git page, then just wait for a few minutes after "npm run deploy" on the master branch. Then, it'll be updated as you expect.

This worked for me!!!! Thank you!!!!

@S-Philp This works perfectly. Thank you.

@betweenbrackets
Copy link

Thank you! 🙏🙏🙏

@amyyalex
Copy link

amyyalex commented Aug 5, 2022

Thanks alot for this, exactly what am looking for🙏🏾

@bibi-elene
Copy link

for some reason all my components got erased by doing so :/ any solution by anyone to restore them?

@Hubrisy
Copy link

Hubrisy commented Oct 24, 2022

thanks a lot

@hossfahad
Copy link

Thank you!

@iabolfazl83
Copy link

it worked! THANK YOU sooooo MUCH

@Elena-Rosa
Copy link

Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment