How to Push a Project to GitHub

Sameer Katija
4 min readMar 1, 2021

--

Photo by Yancy Min on Unsplash

GitHub is the cloud-hosted Git management tool and git is Version Control System as we discussed previously. Github helps us to share and store our code easily. Today we will learn how we can push a project which is stored locally to a remote server or Github.

Before we push the project to Github, we need to configure and install git on our computer and you also need a GitHub account. If you don’t know how to configure and install git read this article. If you have already set it up. Let’s continue.

Step 1: Create a GitHub Repo

In order to push our code to Github, we have to create a Github Repo. You can create Github Repo by simply going to this link. Choose your project name and add a description, if you want to, and click on create the repository.

Step 2: Initialize Git in the project folder

Initialize the project folder as a git repo. To do that you need to navigate to the folder which you want to push on Github. There type the following command

git init

If you have already initialized the repo as git, you can skip this step.

Step 3: Add the files to the git staging area.

Add the files to the git staging area, where all the untracked files will be part of the staging area and will be ready to get tracked.

git add -A

This command will add the file to the staging area and “-A” means you want to include all the files. if you want specific file to be staged then you need to add the file name after git add.

git add abc.txt

Step 4: Commit the staged files.

Commit in git-speak, is the term used for saving changes. Git doesn’t add changes automatically. You need to specify which file and changes, you need to save by adding the files. The commit command saves changes in the local repository of Git.

git commit -m “Initial Commit”

In this command “-m” is used to tell the git, that we are adding a message.

Step 5: Add the remote origin

After creating the repo on GitHub, you will see the windows containing some instructions and also the address of your repo.

After copying the address, you have to add the origin of the remote repo to the local repo by using the following command.

git remote add origin https://github.com/Anonster/jadu-01.git

In your case, the address should be of your GitHub repo.

Step 6: Push to GitHub

Now, it’s time to make our code live. type the following command to push your code to the online repo. Before we push we need to check whether our branch is main or master to check that type the following command.

git branch

In my case, it’s master but in your case, it can be main. so if your branch is “main ”type

git push origin main

If your repo’s branch is “master ”then you need to type

git push origin master

With all that, you have pushed your code to Github. You can share your code with anybody you want.

--

--

Sameer Katija
Sameer Katija

Written by Sameer Katija

Ai enthusiast | MERN Stack Developer | Computer Geek | Tech Blogger | Crypto

Responses (1)