Create Repository
Your project currently exists as a Git repository on your computer. The next step is to create a remote repository on GitHub where that repository can be stored and shared.
On GitHub, create a new repository for the project.
For this guide, the example repository will be called:
pagedeploy
The repository name does not have to be the same as your local project folder, although using matching names usually makes the project easier to recognize.
If your local project already contains its files and already has
a Git commit, create the GitHub repository without adding
another README, .gitignore, or license during
repository creation.
This keeps the new remote repository empty so that your existing local repository can be pushed to it cleanly.
Public vs Private Repository
GitHub repositories can be public or private. This setting determines who can access the repository’s source code on GitHub.
| Repository | Visibility |
|---|---|
| Public | Anyone can view the repository. |
| Private | Access is restricted to people you authorize. |
For this guide, either visibility can be used. A private GitHub repository can still be used as the source repository for a Cloudflare Pages project when the required GitHub connection and permissions are configured.
Repository visibility does not make secrets safe. Never store API keys, passwords, private credentials, or other secrets in the repository.
Connect Local Project
Your local Git repository and the GitHub repository are currently separate repositories. You need to tell Git where the remote GitHub repository is located.
From the root of your local project, run:
git remote add origin https://github.com/USERNAME/pagedeploy.git Replace USERNAME with your GitHub username and make sure the
repository name matches the repository you created on GitHub.
The name origin is the conventional name Git uses for the primary
remote repository. It is simply a local name that points to the GitHub
repository.
Adding the remote does not upload your files. It only tells your local Git repository where the remote repository is located.
git remote
Verify that the GitHub repository has been configured correctly as the remote.
git remote -v
You should see the GitHub repository listed as the
origin remote.
Typically, Git will display the remote URL for both fetching and pushing:
origin https://github.com/USERNAME/pagedeploy.git (fetch) origin https://github.com/USERNAME/pagedeploy.git (push)
At this point, the local repository knows where the GitHub repository is, but your project has not been pushed there yet.
Rename Branch to main
This guide uses main as the primary branch.
Rename the current local branch to
main:
git branch -M main
This renames the current local branch to
main.
You can verify the current branch with:
git branch
The branch marked with * is the branch you are currently using.
In this guide, main
will represent the production branch. Later, feature branches
will be used for development work and merged into
main after review and testing.
First Push
Your local repository is now connected to GitHub and the current branch is
named main. The next step is to send your local commits to the
GitHub repository.
git push -u origin main
The push command sends your local commits to the remote
repository.
The -u option establishes an upstream relationship between your
local main branch and
origin/main.
After this relationship has been established, future pushes from the same branch can normally use the shorter command:
git push
When pushing to GitHub for the first time, GitHub may require you to authenticate your Git client. Follow the authentication method configured for your GitHub account.
After the push completes, refresh the GitHub repository page. You should see the files and commit history from your local project.
What You Have Done
At this point, the basic connection between your local project and GitHub is complete:
Local Project
↓
Local Git Repository
↓
origin
↓
GitHub Repositorygit remote -vCheck which remote repository is configured.
git branch -M mainRename the current local branch to
main.
git push -u origin mainPush the local main branch to GitHub and establish
its upstream branch.
