Elena' s AI Blog

Storing Your Local Project to GitHub

12 Feb 2025 (updated: 03 Jul 2026) / 13 minutes to read

Elena Daehnhardt


Jasper AI-generated art, January 2023

If you click an affiliate link and subsequently make a purchase, I will earn a small commission at no additional cost (you pay nothing extra). This is important for promoting tools I like and supporting my blogging.

I thoroughly check the affiliated products' functionality and use them myself to ensure high-quality content for my readers. Thank you very much for motivating me to write.



TL;DR:
  • A step-by-step guide to creating a Git repository for your local project and pushing it to GitHub using command line and personal access tokens for authentication.

Previous: Part 1 — Git Commands and a Contribution Workflow

Next: Part 4 — Collaboration in GitHub

Pushing a Local Project to GitHub: Overview

Git is a distributed version control system that tracks changes in your files, and GitHub is a hosting service for Git repositories. If you have a Python or any coding/writing project on your local machine and want to share it on GitHub, you can do so using Git and a personal access token (a scoped, revocable string that replaces your account password for command-line access). Let’s create a local Git repository, set up a GitHub repository, and push your code to GitHub!

Prerequisites: GitHub Account and Git Installation

To begin, you must create a GitHub account if you don’t have it yet.

Next, you will have to ensure that Git is installed on your computer. I suggest installing Git since you can use it with GitHub, Bitbucket, GitLab, or any provider. I prefer Git since I use both GitHub and Bitbucket.

You can easily download the Git package from the Downloads webpage. To test that Git is installed correctly, check its version with:

git version
git version 2.34.1

If you like to work with your repositories visually, you can also download any graphical user interface from GUI Clients.

Alternatively, however, it is the most complicated installation. You can install the GitHub Command Line Tool (CLI), an open-source tool that allows you to use GitHub from your command line, helping you save time and avoid context switching. If you don’t yet have the GitHub CLI installed on your system, check the CLI installation instructions.

Steps to Do on GitHub: Token and Repository

So, we have our project stored locally, and we want to keep it on GitHub. To do that, we will have to access GitHub securely with the personal access token, create a new GitHub repository to push our local code and share it when collaborating with our co-workers.

1. Generate a Personal Access Token

A personal access token (PAT) is a scoped, revocable credential string that acts as a password to access and work with GitHub repositories via the command line in the Terminal. GitHub removed support for account-password authentication over HTTPS in August 2021, so a PAT is now required for command-line pushes.

I have a well-detailed post The Token Way to GitHub Security explaining how to create personal access tokens for GitHub.

The process is relatively straightforward:

  1. Go to your GitHub settings (click on your profile picture, then Settings).
  2. Select Developer settings > Personal access tokens (classic).
  3. Click Generate new token.
  4. Set a descriptive name and choose the repo scopes you need.
  5. Click Generate token and copy it. You will use this token instead of your password.

For more information, see the GitHub documentation on creating a personal access token.

2. Create a New GitHub Repository

  1. Go to GitHub and click on New (or +) to create a new repository.
  2. Give your repository a name (e.g., my-python-project, todo_app) and optionally add a description.
  3. Choose if you want it to be public or private.
  4. Do not initialise with a README, license, or .gitignore (since you already committed locally).
  5. Click Create repository.

Steps to Do Locally: git init, commit, and push

Indeed, you will have to have your Python (or any other programming language project, or even your poem, coursework on anything, preferably text-based, since GitHub is a version control tool that is handy for tracking any text changes in time) project folder on your local machine.

1. Initialise a Local Git Repository

Navigate to your project folder in the terminal or command prompt and run:

cd /path/to/your/python-project
git init

This initialises an empty Git repository in your project folder like this:

Initialized empty Git repository in /Users/elena/Documents/git/my_todo_app/.git/

2. Create .gitignore (optional)

Sometimes, we have to exclude specific files from GitHub. For instance, we want to exclude the folder’ .venv` (with all the virtual environment files) from Git.

For this, add an entry to .gitignore file:

.venv/

This tells Git to ignore the entire .venv directory.

You must create the .gitignore file if it does not exist. I like using nano for quick edits :)

3. Stage and Commit Your Code

Add your files to the staging area and commit them:

git add .
git commit -m "Initial commit v1"

Replace "Initial commit v1" with a more descriptive message if desired.

[master (root-commit) 658994d] Initial commit v1
 5 files changed, 136 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 app.py
 create mode 100644 templates/edit.html
 create mode 100644 templates/index.html
 create mode 100644 todo.db

4. Connect Local Repository to GitHub

Copy the repository URL (HTTPS) from GitHub while adding your personal access token we generated above:

git remote add origin https://<your_personal_access_token>@github.com/<your-username>/<your-repo-name>.git

Replace <your-username> and <your-repo-name> with your GitHub details. A filled-in example looks like this:

git remote add origin https://<your_personal_access_token>@github.com/edaehn/todo_app.git

5. Push Your Code to GitHub

Push your local commits to the GitHub repository:

git push -u origin master

Since we used our personal access token, we will not be prompted for a GitHub username and password. Everything will go smoothly:

Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 10 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 2.31 KiB | 2.31 MiB/s, done.
Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/edaehn/todo_app.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

Common Git Push Errors and Fixes

error: remote origin already exists

This means a remote named origin is already configured. Point it at the correct URL instead of adding a duplicate:

git remote set-url origin https://<token>@github.com/<username>/<repo>.git

Or remove and re-add it:

git remote remove origin
git remote add origin https://<token>@github.com/<username>/<repo>.git

error: src refspec master does not match any

This appears when you push before making a commit, or when your default branch is main rather than master. Commit first, then push the branch that actually exists:

git add .
git commit -m "Initial commit v1"
git push -u origin main   # use 'master' if that is your branch name

Check your current branch name with git branch --show-current.

Verify Your Repository

  1. Go back to GitHub and visit your newly created repository page.
  2. Confirm your files are visible and that your commit history is as expected.

Storing a Project on GitHub FAQ

How do I push an existing local project to GitHub?

Run git init in the project folder, then git add . and git commit -m "Initial commit". Create an empty repository on GitHub, connect it with git remote add origin https://<token>@github.com/<username>/<repo>.git, and push with git push -u origin master.

Why use a personal access token instead of a GitHub password?

GitHub removed support for account-password authentication over HTTPS in August 2021. A personal access token (PAT) acts as a scoped, revocable password for command-line and API access, so you authenticate with the token instead of your account password.

How do I fix ‘‘error: remote origin already exists’’?

The remote named origin is already set. Update its URL with git remote set-url origin <new-url>, or remove it first with git remote remove origin and then re-add it with git remote add origin <url>.

Should I commit my .venv folder to GitHub?

No. Add .venv/ to a .gitignore file so the virtual environment is excluded. If it was already committed, untrack it with git rm -r --cached .venv and commit the change.

Conclusion

Pushing a local project to GitHub is a repeatable six-command workflow: git init, git add, git commit, git remote add origin, and git push -u origin, authenticated with a personal access token rather than a password. You have successfully created a Git repository for your excellent, possibly, Python project and uploaded it to GitHub. Remember to keep your personal access token secure and use Git commands to maintain version control effectively. Please don’t commit or publish your access tokens openly :)

Did you like this post? Please let me know if you have any comments or suggestions.

Git posts that might be interesting for you




Related tools you may want to try next.

CustomGPT.AI is a very accurate Retrieval-Augmented Generation tool that provides accurate answers using the latest ChatGPT to tackle the AI hallucination problem.

References

  1. GitHub Homepage
  2. Download Git from git-scm.com
  3. Git GUI Clients from git-scm.com
  4. GitHub CLI Installation Instructions
  5. The Token Way to GitHub Security
  6. GitHub Documentation: Creating a personal access token
  7. GitHub Documentation: Getting started with Git
desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2025) 'Storing Your Local Project to GitHub', daehnhardt.com, 12 February 2025. Available at: https://daehnhardt.com/blog/2025/02/12/store-your-local-project-to-github/
All Posts