Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@JorgeTheCreator

This comment has been minimized.

Copy link

commented Aug 9, 2016

awesome! just what i was looking for.

@PrinceYoulou

This comment has been minimized.

Copy link

commented Sep 23, 2016

Thanks, it helped me a lot!!

@allen30331

This comment has been minimized.

Copy link

commented Nov 9, 2016

Thank you, it helped me a ton!

@JawadS

This comment has been minimized.

Copy link

commented Dec 11, 2016

Sorry, but does make gh-pages permanently up to date with that branch?

@dhoel

This comment has been minimized.

Copy link

commented Dec 18, 2016

thx!!!

@mskarthi95

This comment has been minimized.

Copy link

commented Jan 3, 2017

yeah ! github slowly update sometimes
when use settings > Choose Branch and Save Github pages

@Emichira

This comment has been minimized.

Copy link

commented Jun 15, 2017

Many thanks.

@ashu4code

This comment has been minimized.

Copy link

commented Aug 27, 2017

fatal: 'orgin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

@leahpjoyce

This comment has been minimized.

Copy link

commented Sep 2, 2017

Thank you..

@danstepanov

This comment has been minimized.

Copy link

commented Sep 18, 2017

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.

@somethingsmart

This comment has been minimized.

Copy link

commented Oct 4, 2017

Thank you so much.

@mathvbarone

This comment has been minimized.

Copy link

commented Oct 31, 2017

@mandiwise and @danstepanov thank you!

@ricvergara

This comment has been minimized.

Copy link

commented Nov 6, 2017

Thanks you so much, It was terrible to get that information in Spanish, let me translate it

@kcee403

This comment has been minimized.

Copy link

commented Nov 14, 2017

Only thing it adds a static folder and causes other problems if you didn't have a static from before. If you don't have one don't use try this out.

@coreysnightout

This comment has been minimized.

Copy link

commented Feb 14, 2018

i keep getting an error when pushing gh-pages
"error: failed to push some refs to 'https://github.com/coreysnightout/portfolio-project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes "

its telling me to pull but im afraid to pull and lose my remote master work. any tips? thank you!

@akapne01

This comment has been minimized.

Copy link

commented Mar 4, 2018

Thank you, this helped a lot! 👍

@danielmanfred

This comment has been minimized.

Copy link

commented May 21, 2018

Thank u bro

@shireeshglug

This comment has been minimized.

Copy link

commented Jul 25, 2018

Do I need to create the gh-pages branch before I check it out ....

@shireeshglug

This comment has been minimized.

Copy link

commented Jul 25, 2018

Is this applied for react apps too ?

@vijay07roy

This comment has been minimized.

Copy link

commented Sep 27, 2018

Is this applied for react apps too ?

Yes

@vijay07roy

This comment has been minimized.

Copy link

commented Sep 27, 2018

Do I need to create the gh-pages branch before I check it out ....

Yes

@mikeshatch

This comment has been minimized.

Copy link

commented Sep 29, 2018

I get the following error:

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

The following will fix that, but it's not recommended from what I've read:

git push -f origin gh-pages

Is there a way to fix this error without doing this? It seems to mess things up. On one try it doubled the amount of files, and on the second the scss folder didn't transfer over.

@sjnelson1

This comment has been minimized.

Copy link

commented Oct 15, 2018

Thank you!

@Rosavf

This comment has been minimized.

Copy link

commented Nov 13, 2018

Thank you ;) very good

@sailesh97

This comment has been minimized.

Copy link

commented Jan 5, 2019

$ git checkout gh-pages
error: pathspec 'gh-pages' did not match any file(s) known to git
I m getting this error .Can anyone help??

@jessepackwood

This comment has been minimized.

Copy link

commented Jan 25, 2019

sailesh97 I had the same error and I just needed to run

git fetch

That brought the branch down locally for me

@VinciLin

This comment has been minimized.

Copy link

commented Feb 7, 2019

thanks!

@cariepigeon

This comment has been minimized.

Copy link

commented Feb 8, 2019

Thank you! This is exactly what i needed!!

@mdestafadilah

This comment has been minimized.

Copy link

commented Feb 18, 2019

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.

do Still work?, i never try..

@ahmedohadi

This comment has been minimized.

Copy link

commented Mar 29, 2019

I get the following error:

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

The following will fix that, but it's not recommended from what I've read:

git push -f origin gh-pages

Is there a way to fix this error without doing this? It seems to mess things up. On one try it doubled the amount of files, and on the second the scss folder didn't transfer over.

Thank a lot!

@Edwin-Pratt

This comment has been minimized.

Copy link

commented May 22, 2019

I am so grateful for finding this! I kept on getting conflicts because I was just using git pull without another git push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.