DEV Community

Cover image for Deploy a React App as a Github User Page with Yarn

Deploy a React App as a Github User Page with Yarn

JavaScriptErika on May 29, 2018

tldr; see Solution I've been working on redoing my portfolio site, it's still a WIP - that being said here it is so far. I need to polish my portf...
Collapse
 
pbkarlsson profile image
Philip Karlsson

Great!

Yesterday I got the idea that I'd replace my old Jekyll based personal GH-page with React site built with GatsbyJS. Unfortunately I forgot the whole point with version control and deleted the old site's repository before building the new one. I ended up not liking Gatsby, so currently I have no site. So, yeah, this is couldn't have come at a better time.

Thanks!

Collapse
 
javascripterika profile image
JavaScriptErika

Awesome!!!

Haha, I did the same thing with my previous user page; I deleted my repo, and started fresh (with my current project) as I had to do something super wonky with the build files with my previous setup (I really had no idea what I was doing at the time)!

I definitely feel confident with this method now, especially for any needed updates or complete redesigns in the future.

Collapse
 
goughjo02 profile image
goughjo02 • Edited

Great article.

When using react-router, have you tried adding a redirect, from '/repository-name' to '/home' to solve the final issue?

Edit

I have tried this and it works. add <Route exact path="/your-github-repo" render={() => <Redirect to="/" />} /> to your routes

Collapse
 
coffeegerm profile image
David Yarzebinski

Would this work just as well with Vue? or just React?

Collapse
 
javascripterika profile image
JavaScriptErika

I did some digging around, here's what I found for vue:

vue-gh-pages
npmjs.com/package/vue-gh-pages

and

vuepress.vuejs.org/guide/deploy.ht...

^ This method appears to be the most straightforward for vue, as you don't need to add any dependencies. I'd still recommend creating a source branch as you'd be pushing your build files directly to master.

Collapse
 
rik96 profile image
rik-96

This was really helpful.! I've been trying to add a custom domain name to my repo. This article saved at least me a couple of hours. However, I don't understand why we need to be in source to run build?

Collapse
 
moussaabmoulim profile image
moussaab moulim

i have the same question

Collapse
 
cclin profile image
Catherine Lin

Hi, thanks for writing this tutorial!

I followed the instructions but I'm still getting an error after running deploy from the source branch.

'fatal: A branch named 'master' already exists.'

Do you have any idea why?

Collapse
 
cclin profile image
Catherine Lin

Never mind , I managed to get it work. Thanks again for the instructions! :)

Collapse
 
hrkucuk profile image
Hakki Riza Kucuk • Edited

I am having the exact same problem right now but I could not get it work. Could you please share how did you solve it?

EDIT: for anybody who would face the same problem: refer here
github.com/tschaub/gh-pages#when-g...

Thread Thread
 
hrkucuk profile image
Hakki Riza Kucuk

I could not solve this problem so I came up with another solution: -check out a new branch called "source" which is an exact copy of "master".
-deploy the site to branch "gh-pages" with usual gh-pages npm module. (I use npm in my example, but the script is same.)

  • rebase "master" to "gh-pages" and simply push it. So "master" will have what "gh-pages" will have.

It is a not a clean solution though. Any feedback is much appreciated.

Collapse
 
danieljamesross profile image
danieljamesross

I followed your excellent tutorial and successfully published my react app back in May 2020.

I recently updated the app and hit 'yarn deploy', but the site would only show the README.

After unsuccessful attempts to fix, I eventually asked GitHub. They replied within 30 mins (excellent!) with the following fix which I thought I'd share.

Thanks for the tutorial, fix below.

"We recently rolled out a change that allows you to select any branch to publish Pages from. Unfortunately, we have identified a bug with this change that affects user site repositories whose default branch was not master. In cases like this, the publishing source for Pages gets set as the default branch instead of master, which is what has happened to you.

You will need to set the publishing source back to the master branch by following the steps here

Once you do that, it shouldn't change again."

Collapse
 
arodriguezhacks profile image
Angie Rodriguez

Useful article for the most part; however, I don't understand this step:

"Switch to master in the terminal, git merge source or whatever branch you want, switch to your source branch and and run:

$ yarn deploy"

If this step instructs you to merge the source branch into the master branch, then the master branch is ahead by 1 commit of 'origin/master':
"$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)"

So I tried pushing the master branch with 'git push origin master', but I receive an error which says I would have to first do a git pull, yet I know from trial and error that'll be a bad move, pulling down 5k items hence the reason why I searched the internet and finally found this helpful article.

I'm just concerned about why my master branch is not on par with the origin/master branch on Github, but maybe it's not so big a deal ?

Collapse
 
youngkidwarrior profile image
VictorGinelli

same

Collapse
 
itscosmas profile image
Cosmas Gikunju • Edited

Hey thanks. This saved me pulling my hair and digging over google only to find solution for project sites.

Collapse
 
shavrin profile image
Kacper Olek

Struggled with that a lot, now it works!
Thank you!

Collapse
 
cat profile image
Cat

I absolutely needed this. I learned (the hard way) that directly connecting the app to GitHub was a mistake. Thank you for this!

Collapse
 
javascripterika profile image
JavaScriptErika

You're welcome - thank you for your feedback!!! I got hung up on it after working on my portfolio and wanting to test it out - it was frustrating because it didn't feel like there was cohesive documentation out there and I wanted to fix that problem! :)

Collapse
 
tsuzukayama profile image
Tiago Suzukayama

Great post! I was looking for a tutorial on how to do this just now. Thanks!

Collapse
 
javascripterika profile image
JavaScriptErika

Awesome - thank you so much!
I JUST updated the article to hopefully save some people some time if you are using React Router and deploying as a user page! Cheers to a successful deploy!

Collapse
 
markphughes17 profile image
Mark Hughes

Great post, I was having a bit of trouble with this myself, really helped me out :)

Collapse
 
marsroamer profile image
MarsRoamer

You're awesome!! Thank you for posting this tutorial! I've been fighting with this and you cleared it up, and made it make sense. Thanks again!

Collapse
 
jackrussell1996 profile image
Jack Russell

Works perfectly,thanks!

Collapse
 
zumdewald profile image
ZumDeWald

Excellent article! Worked on the first try for me.

Collapse
 
francodecafe profile image
Fran Salinas

Thank you so much! I found this a very elegant solution and in just a few steps ❤️️

Collapse
 
raymag profile image
Carlos Magno

Thank you! I was having some issues while rebuilding my github page with react, thanks you I solved the problem. It helped me a lot!

Collapse
 
arrbxr profile image
Abhishek Raj Ravi

i get an Erro -> Unexpected token : in JSON at position 10

Collapse
 
blaney83 profile image
Benjamin Laney

Awesome! Thanks for being easy to understand, direct and thorough. Will be sharing.

Collapse
 
thevenice profile image
Prakash Pawar

after 5 articles this one worked. thanks alot <3.

Collapse
 
miguelriosoliveira profile image
Miguel Rios

After hours and hours searching for this issue, you finally gave me the right answer, thank you so much! <3

Collapse
 
ajayg415 profile image
Ajay

Thanks a lot!
You helped me how to deploy website in user page...