How to Create gh-pages Branch in GitHub
Creating a gh-pages branch in GitHub is a common practice for deploying static websites or documentation. This branch allows you to separate your main development branch from the website content, ensuring that your code remains clean and free from any website-related changes. In this article, we will guide you through the process of creating a gh-pages branch in GitHub.
Step 1: Clone your repository
Before you start, make sure you have a GitHub repository. If you don’t have one, you can create one by visiting GitHub and clicking on “New repository.” Once you have your repository, clone it to your local machine using the following command:
“`
git clone
“`
Replace `
Step 2: Create a new branch
Navigate to the cloned repository directory in your terminal or command prompt. Then, create a new branch named `gh-pages` using the following command:
“`
git checkout -b gh-pages
“`
This command creates a new branch and switches to it at the same time.
Step 3: Add your website content
Now that you are on the `gh-pages` branch, you can add your website content to the repository. This can be done by creating a new directory for your website and adding HTML, CSS, JavaScript, and any other files you need. Once you have added your content, commit the changes to the `gh-pages` branch:
“`
git add .
git commit -m “Add website content”
“`
Step 4: Push the gh-pages branch to GitHub
After committing your changes, push the `gh-pages` branch to your GitHub repository:
“`
git push origin gh-pages
“`
This command pushes the `gh-pages` branch to the remote repository on GitHub.
Step 5: Configure your GitHub Pages
Now that you have pushed the `gh-pages` branch to GitHub, you can configure your GitHub Pages. Go to your GitHub repository settings and find the “GitHub Pages” section. Choose the branch you want to use for your website (in this case, `gh-pages`) and save the changes.
GitHub will automatically build your website and make it available at a URL like `https://
Conclusion
Creating a gh-pages branch in GitHub is a straightforward process that allows you to separate your code from your website content. By following these steps, you can easily deploy static websites or documentation on GitHub Pages. Happy coding!