GitHub is a powerful platform for storing and sharing your code. By uploading your website files to GitHub, you not only create a backup but also make collaboration and deployment much easier. Here’s how to do it:
- Log in to your GitHub account. If you don’t have one, create an account first.
- Click on the “New” button in the top-left corner or navigate to Create a New Repository.
- Give your repository a meaningful name (e.g.,
my-website). - Add an optional description and decide whether to make it public or private.
- Check the box to initialize the repository with a
READMEfile if desired. - if you have an existing repository just make sure you have pushed all changes
- Open your project folder locally on your computer.
- If you’re using Git for version control, open a terminal in the project directory and initialize Git:
- Add all your files to the repository:
- Commit your changes:
git commit -m "Initial commit"
- Link your local repository to the GitHub repository by adding the remote URL (replace
your-usernameandyour-repositorywith your details):
git remote add origin https://github.com/your-username/your-repository.git
- Push your files to GitHub:
git push -u origin main
- If your default branch isn’t
main, use the branch name you created instead.
Now your website’s code is safely stored on GitHub. 📦 The next step is to deploy it.
GitHub Pages is a free and simple way to host your static website directly from your GitHub repository. Follow these steps to get your website live:
create new action file for the code
- Once enabled, GitHub Pages will provide a URL for your live site
https://your-username.github.io/your-repository/ - Note that it might take a few minutes for your website to go live.
name: Build and Deploy on: push: branches: [ "main" ] pull_request: branches: [ "main" ] workflow_dispatch: # Manual trigger from GitHub UI jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' - name: Install dependencies run: npm install - name: Build React App run: npm run build - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./distIf you have a custom domain, you can link it to your GitHub Pages site by adding a CNAME file to your repository or configuring your domain's DNS settings. GitHub's documentation provides detailed steps for this process.
get your domain from service provider add its name in the “name section”
and it will give you a cname record copy it go tyo your dns provider and paste it make sure you are selecting lowest ttl and click update
DNS takes time to update after it is done anyone can acess your site
By uploading your website to GitHub and deploying it with GitHub Pages, you’ve made your project accessible to the world. It’s a big step forward in your web development journey, and it gives you a foundation to share, improve, and build upon your work. Happy coding! 🚀
Share this with your friends
Loved it click the button to subscribe
Originally published at https://balasaisigireddy.substack.com.
Comments
Post a Comment