In this post, we will show you how to push a project to GitHub. Whether you’re a beginner learning Git or an experienced developer, pushing your code to GitHub is a key step in sharing and managing your projects. Pushing allows you to upload your project to the cloud, making it easier to collaborate with others and track version changes over time.
How do I push an existing project to GitHub?
There are multiple ways to push an existing project to GitHub. For example, you can clone a GitHub repository on your local machine and copy existing project files there, or invoke git init
and git remote add
commands to update remote references. Alternatively, you can use Visual Studio Code’s built-in Git integration to manage and push your code without leaving the editor.
How to Push a Project to GitHub
In the following sections, we will cover two different methods to push existing code to GitHub, so you can choose the one that suits you best.
To push a project to GitHub, you may use the following methods:
- Using Git Command Line
- Using GitHub Desktop App
Let us see these in detail.
1] Using Git Command Line
This method uses Git commands in the terminal (Git Bash) to initialize your project as a Git repository, link it to a GitHub repository, and push your code.
Here we assume you already have a GitHub account and Git installed on your system.
Open File Explorer and navigate to your project folder. Right-click inside the folder (any blank area) and select “Git Bash Here”.
This will open Git Bash with the working directory already set to your project folder. Run the following command to initialize Git in your project folder:
git init
The above command creates a hidden .git folder where Git tracks all version history.
Next, run the following command to stage all the files in your project to prepare them for commit:
git add .
Next, create your first commit with a meaningful message:
git commit -m "Initial commit"
You’ve now saved your project’s current state into Git’s version history locally.
Next, go to GitHub and create a new repository.
Make sure you don’t initialize it with a README, .gitignore, or license. Copy the repository URL (choose HTTPS).
Go back to Git Bash and run:
git remote add origin https://github.com/sangeetaghera2710/push-project-properly-demo.git
(Replace the URL with your actual repository link.)
This command connects your local project with the GitHub repository by adding a remote reference named “origin”. Now that your local project is linked to the remote GitHub repository, you can push your commits through this command:
git push -u origin main
The above command uploads your local main branch to the origin remote (your GitHub repo) and sets it to track future changes.
Note: In older Git setups, the default branch name may be master instead of main. If your branch is called main, the above push command will work. If your branch is called master, use this instead:
git push -u origin master
If you’d like to switch to the modern default (main), you can rename the branch before pushing:
git branch -M main git push -u origin main
Now, when you refresh your GitHub repo page in the browser, you’ll see all your project files listed there, just like they appear in your local folder.
Note: There’s another easy way to push an existing project to GitHub. First, create a new repository on GitHub and clone it to your computer. Then, simply copy your existing project files into the cloned folder, commit the changes, and push them back to GitHub. This method avoids setup errors and is great for beginners.
2] Using GitHub Desktop App
If you prefer a visual workflow to manage repositories, commits, and pushes, this method is for you. GitHub Desktop is an official app developed and maintained by GitHub. It provides a graphical interface that simplifies Git operations without needing to use the command line.
To push a project using GitHub Desktop, follow these steps:
Download and install GitHub Desktop using this link. Launch the app and sign in with your GitHub account.
Click Add local repository, and select the folder containing your existing project (which you already pushed using Git Bash).
Next, open the project folder in Visual Studio Code and add a new file (e.g., about.html).
Switch back to GitHub Desktop. It will automatically detect the newly added file and list it under Changes.
Enter a commit message like “Add about.html page”. Click Commit to main (or your current branch name).
After committing, click the Push origin button in the top right corner. Your changes will be uploaded to the connected GitHub repository.
Open your repo on GitHub.com and refresh to see the new file.
Note: If you’re starting from scratch, create a new repo in GitHub Desktop, move your project files into it, then commit and push. GitHub Desktop will track changes and make it easy to push updates as you go.
I hope you find this useful.
Read: How to merge two branches in Git?
How do I import a project into GitHub?
To import a project into GitHub, you can either use the GitHub Importer (a web-based tool that helps you import repositories from other sources) to copy an existing remote repository from another platform or push a local project using Git, GitHub Desktop, or VS Code. For local projects, initialize Git, connect to a GitHub repo, and push your code.
Read Next: How to resolve Merge Conflicts in Git.