Hey fellow readers!
If you are a newbie to GitHub and the open-source world, then you should learn git commands as well. Believe me, that is really easy if you do with me.
In this post, i will teach you how to deploy your projects on github pages(gh-pages) using git. So a lot know and a lot to discuss as always
So for this you need:
- a github account
- git windows application (since i am a window user, i will be using git window commands).
So lets start the deployment with git. For this, launch git application on windows.
Set your username with this command
git config --global user.name "Vikas Singh"Set your email id with this command
git config --global user.email "abc@example.com"Switch to the directory where you want to do the entire deployment work. I will suggest creating a new directory for that purpose.
cd Documents
cd vikasgit
Like here I have created the folder named "vikasgit" in my "Documents" folder. So I used the "cd" command 2 times. And to create new folder i used the command below:
mkdir vikasgit
Now initialize an empty git repository in that folder "vikasgit"
git init_Clone the repo on which you want to deploy your projects.
git clone [repo link]Now again switch to the repo.
cd [repo-name]Add your project files manually in the repo which is now created in your system locally.
Now switch to the GitHub-pagesbranch. This command is used to switch to any branch.
git checkout gh-pages
NOTE: To create a new branch use this command
git branch -b [branch-name]
Stage the changes made recently.
git add .Commit the changes
git commit -m "first commit"Check the status of the current repo.
git statusFinally push the new changes.
push origin gh-pages
NOTE: Check the log (history of the current repo)
git log
Follow me on Instagram
https://www.instagram.com/p/CFqrvobFlsL/?igshid=j3lhn2qi3og0
Follow on Twitter
https://mobile.twitter.com/_SinghVikas_
You can read my previous post here!
https://dev.to/vkassingh/hacktoberfest-get-more-than-a-t-shirt-1cj0
Top comments (2)
Remember to go to Settings of your repo and enable GitHub Pages on gh-pages branch.
For more background on why to commit to the gh-pages branch, this is useful if you have a React or Vue or other SPA or static site output, then you build to an output directory and then commit that to your gh-pages branch so you can serve your app as a GitHub Pages site.
Also if you upload markdown and HTML to master, you can select master and GitHub Pages will build the site for you as HTML pages. You can also turn your site into a Jekyll site if you use templating and configs from Jekyll. Again, no gh-pages branch needed as GH will build a Jekyll 3.9 site for you
thanks Mike for adding a good point,