DEV Community

Vikas Singh
Vikas Singh

Posted on

How to deploy your local project on github using git

git and github

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:

  1. a github account
  2. 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.

  1. Set your username with this command
    git config --global user.name "Vikas Singh"

  2. Set your email id with this command
    git config --global user.email "abc@example.com"

  3. 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

  1. Now initialize an empty git repository in that folder "vikasgit"
    git init_

  2. Clone the repo on which you want to deploy your projects.
    git clone [repo link]

  3. Now again switch to the repo.
    cd [repo-name]

  4. Add your project files manually in the repo which is now created in your system locally.

  5. 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]

  1. Stage the changes made recently.
    git add .

  2. Commit the changes
    git commit -m "first commit"

  3. Check the status of the current repo.
    git status

  4. Finally 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)

Collapse
 
michaelcurrin profile image
Michael Currin

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

Collapse
 
vkassingh profile image
Vikas Singh

thanks Mike for adding a good point,