Push to GitHub
GitHub is a platform for hosting and version-controlling code. In this guide, you will create a GitHub account, set up a repository, and push your GatsbyCar project.
This step is required before deploying to Netlify, because Netlify pulls your code from GitHub.
Why GitHub
GitHub serves three purposes for your GatsbyCar project:
- Backup — your code is stored safely online
- Version control — you can track changes and revert if needed
- Deployment source — Netlify pulls code from GitHub to build your website
Without GitHub, you cannot use Decap CMS in production mode. Decap CMS uses Git Gateway to commit changes back to your repository.
Step 1: Create a GitHub Account
If you already have a GitHub account, skip to Step 2.
- Open your browser and go to https://github.com
- Click Sign up in the top right corner
- Enter your email address
- Create a password (at least 15 characters, or 8 characters with a number and lowercase letter)
- Enter a username (this will be part of your repository URL)
- Complete the verification puzzle
- Click Create account
- Check your email for a verification code
- Enter the code on GitHub
- Complete the onboarding questions (you can skip most of them)
Your GitHub account is now ready.
Step 2: Install Git
Git is a version control tool that GitHub uses. You need it installed on your computer.
Check if Git is already installed:
Open your terminal in VS Code and type:
git --versionIf you see something like git version 2.40.0, Git is installed. Skip to Step 3.
If Git is not installed:
For Windows:
- Go to https://git-scm.com/download/win
- Download the installer
- Run it and follow the wizard
- Keep all default settings
- Click Finish
- Restart VS Code
For Mac:
- Open Terminal
- Type
git --version - If not installed, macOS will prompt you to install Command Line Tools
- Click Install
- Wait for the installation to complete
For Linux:
sudo apt install gitVerify installation:
git --versionStep 3: Configure Git
Set your Git identity. This will be attached to every commit you make.
In your terminal, type:
git config --global user.name "Your Name"Press Enter. Replace Your Name with your actual name.
Then type:
git config --global user.email "your@email.com"Press Enter. Replace your@email.com with your GitHub email.
Verify your configuration:
git config --listYou should see your name and email listed.
Step 4: Create a New Repository on GitHub
- Log in to GitHub at https://github.com
- Click the + icon in the top right corner
- Click New repository
Fill in the form:
Repository name
- Example:
gatsbycarormy-car-rental-site - Use lowercase letters and hyphens
- No spaces
Description (optional)
- Example:
Car rental website built with Gatsby and Decap CMS
Visibility
- Select Public or Private
- Public — anyone can see your code (recommended for open source)
- Private — only you can see your code (recommended if you want to keep it secret)
Initialize this repository with:
- Leave all checkboxes unchecked
- Do not add README, .gitignore, or license
Click Create repository.
You will see a page with setup instructions. Keep this page open.
Step 5: Initialize Git in Your Project
Open VS Code with your GatsbyCar project folder.
Open the terminal and make sure you are in the project root folder. Type:
pwdYou should see your project path, like /Users/yourname/projects/gatsbycar.
Initialize Git:
git initYou should see:
Initialized empty Git repository in /path/to/gatsbycar/.git/Step 6: Check the .gitignore File
A .gitignore file tells Git which files to ignore. GatsbyCar already includes one.
Open .gitignore in VS Code. It should contain:
.cache/
public/
node_modules/
.DS_Store
*.logThis means Git will not track those folders. That is correct — you do not want to commit node_modules or build output.
If .gitignore does not exist, create it in the project root with the content above.
Step 7: Stage All Files
Stage all files for the first commit:
git add .The dot (.) means "add all files in the current directory".
Check what will be committed:
git statusYou will see a list of files in green — these are staged for commit.
Step 8: Create the First Commit
Commit the staged files with a message:
git commit -m "Initial commit"You should see output like:
[main (root-commit) abc1234] Initial commit
150 files changed, 12000 insertions(+)
create mode 100644 gatsby-config.js
...Step 9: Connect to GitHub Repository
Go back to your GitHub repository page. You will see commands under "…or push an existing repository from the command line".
Copy the URL that looks like:
https://github.com/your-username/gatsbycar.gitIn your VS Code terminal, type:
git remote add origin https://github.com/your-username/gatsbycar.gitReplace your-username and gatsbycar with your actual values.
Verify the remote:
git remote -vYou should see:
origin https://github.com/your-username/gatsbycar.git (fetch)
origin https://github.com/your-username/gatsbycar.git (push)Step 10: Push to GitHub
Rename your local branch to main (GitHub uses main as the default):
git branch -M mainPush your commit to GitHub:
git push -u origin mainYou may be asked to authenticate. GitHub no longer accepts passwords for Git operations. You need a Personal Access Token.
Step 11: Create a Personal Access Token
If the push fails with an authentication error, follow these steps:
- Go to https://github.com/settings/tokens
- Click Generate new token
- Click Generate new token (classic)
- Enter a note, like
GatsbyCar project - Set expiration to No expiration or 90 days
- Check the repo checkbox (this grants full repository access)
- Click Generate token at the bottom
- Copy the token immediately — you will not see it again
When Git prompts for password:
- Username: your GitHub username
- Password: paste the Personal Access Token
Save the token somewhere safe. You will need it again.
Alternative: Use GitHub Desktop
If you prefer a visual interface, download GitHub Desktop at https://desktop.github.com. It handles authentication automatically.
Step 12: Verify the Push
- Go back to your GitHub repository page
- Refresh the page
- You should see all your files listed
- The commit message "Initial commit" should appear
Your code is now on GitHub.
Step 13: Make Future Changes
After the initial setup, the workflow for future changes is:
git add .
git commit -m "Describe your changes"
git pushExample:
git add .
git commit -m "Update homepage content"
git pushEvery time you run git push, your changes go to GitHub. If you have Netlify connected, it will automatically rebuild your website.
Common Issues and Solutions
Issue: "fatal: not a git repository"
Solution: You are not in the project folder. Run cd to navigate to the project root, or reopen the folder in VS Code.
Issue: "Permission denied (publickey)"
Solution: Use HTTPS instead of SSH. Change the remote:
git remote set-url origin https://github.com/your-username/gatsbycar.gitIssue: "Authentication failed"
Solution: Use a Personal Access Token instead of password (see Step 11).
Issue: "Failed to push some refs"
Solution: The remote has changes you do not have locally. Pull first:
git pull origin main --rebase
git pushIssue: "Nothing to commit, working tree clean"
Solution: You have not made any changes since the last commit. Check git status.
Issue: Committed node_modules by mistake
Solution: Add node_modules/ to .gitignore, then:
git rm -r --cached node_modules
git commit -m "Remove node_modules"
git pushBest Practices
Commit often Make small commits with clear messages. Instead of one giant commit, commit each feature or fix separately.
Write clear commit messages
- Good:
Add Rolls-Royce Phantom to fleet - Bad:
Update
Pull before pushing
If you work on multiple computers, always git pull before git push to avoid conflicts.
Keep .gitignore updated
If you add new files that should not be tracked, add them to .gitignore.
Do not commit secrets Never commit API keys, passwords, or private tokens. If you accidentally commit one, rotate it immediately.
Understanding Git Basics
| Command | What It Does |
|---|---|
git init |
Initialize a new Git repository |
git add . |
Stage all changes |
git commit -m "message" |
Commit staged changes |
git push |
Send commits to GitHub |
git pull |
Get latest changes from GitHub |
git status |
Show current state |
git log |
Show commit history |
git diff |
Show unstaged changes |
Next Step
Your code is now on GitHub. Proceed to:
Deploy to Netlify
Need Help?
If you get stuck, contact us:
- Email: creativebydre@gmail.com
- Custom project: https://www.fiverr.com/creativitas/create-your-custom-website-and-app
RentCar