DEV Community

Sameer Katija
Sameer Katija

Posted on • Updated on • Originally published at sameerkatija.Medium

How to Push a Project to GitHub using terminal

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.

Create a GitHub repo

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
Enter fullscreen mode Exit fullscreen mode

initialize github

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
Enter fullscreen mode Exit fullscreen mode

Add the files to git staging area

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

git add abc.txt
Enter fullscreen mode Exit fullscreen mode

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”
Enter fullscreen mode Exit fullscreen mode

commit the staged files

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.

Address of GitHub 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
Enter fullscreen mode Exit fullscreen mode

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

Git add remote origin

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
Enter fullscreen mode Exit fullscreen mode

Picture showing repo branches

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
Enter fullscreen mode Exit fullscreen mode

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

git push origin master
Enter fullscreen mode Exit fullscreen mode

Git push origin master

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

Top comments (1)

Collapse
 
m4cd4r4 profile image
m4cd4r4

Thanks!