Learn to Push Your Code To GitHub
Tags: github, opensource, git
Published: 2021-03-26 18:43:24

## Introduction

We have all heard of **[GitHub](https://github.com)**, right?

The **beautiful UI**, the development environment created by all those **ongoing** projects and their **huge** codebases, makes GitHub one of a kind platform for **collaboration** and to **share** your ideas with the world.
It has now become an essential part in a developer's life and especially in times like these where 
'**Work from Home**' is now becoming the 'New Normal'.

But, sometimes these all can become a little overwhelming for young developers, who are just starting their journey and stepping into the world of **Open Source Software Development**.

One of the common areas, where beginners get stuck is **uploading** their written code files to GitHub!
Derived the **logic**, written some **code**, and the project is **ready** to be uploaded. But then the question arises 
'**How exactly am I supposed to push/upload these files to my  repository?**'🧐

I've got you covered there! 
In this article we'll be covering the **simple** and **step-by-step** process of pushing your code files to your GitHub repository without any hassle.

**Let's jump right into it!**⚡️

## The Way To Go

Alright, so for handling these processes and working with files, we use what is called as '**Git**'.
It is **version control system**, which basically designed to handle everything from small to very large projects with **speed** and **efficiency**.

For pushing the files to GitHub, learning the **Git commands** and using the 
**terminal/command** 👾  line for the task is a more efficient way rather than the traditional way of doing things using **GUI**.

## Step-By-Step Guide

Follow this **guide** and **tick the checkbox** once you complete each step. At the end, you'll achieve what you were looking for!

**Creating a new repository on GitHub**

- [ ] To do that, click on the **`+`** sign besides the profile picture on the GitHub page

![](https://i.imgur.com/Mge9sr0.png)

- [ ] Select '**new repository**'
- [ ] Give your repository a name. For this example, lets go with "**Practice**"
- [ ] Click on '**create repository**'

After this, a new page with some information would appear.
This we'll be using further ahead.

**Navigating to your project folder and setting it as your current working directory**

Using the command line, set your project folder as your **current working directory** as follow:

- [ ] use the `ls` command which lists down all the files and folder in the current directory.
- [ ] Once you find your project folder, use the `cd ` command to **change the directory** and set this as current working directory.

![](https://i.imgur.com/uj92Hab.png)


Now, the project folder has become current working directory and we can start using the **Git commands**.

**Initialise the directory as a Git repository**

Basically in this step, we are **activating/creating** a Git environment in our folder, in order to use the commands. 

- [ ] using the command `git init` in the command line, the Git repository is **initialised**

![](https://i.imgur.com/EzcJ35u.png)


**Adding your files to the Git Repository**

Now, the aim is to move all our files to this repository. 

- [ ] use the command `git add .` , which will add all the files to the **Git repo** that we created
- [ ] if you want to check whether the files have been added successfully, we use a command `git status` .

This will display all the added files in **green colour** if the process is carried out successfully.

![](https://i.imgur.com/QGESZUT.png)


**Commit the files in the repository**

**Commit** means to **save the changes** to the local repository.
This is an important process when it comes to saving your progress along the way, when using Git.

- [ ] run the command `git commit -m "-message-"` in order to save the changes that was done to the Git repository.

**Adding the URL of your remote repository** 

By remote repository, means the repository that we have created on the **GitHub account**.
Here, the aim is to add the link for the GitHub repository where we have push our files to. 
(**the link is available on the repo page on GitHub**)

![](https://i.imgur.com/LP0Wu6n.png)

- [ ] using the command `git remote add origin (URL) `, we are adding the remote repository with the given URL.

![](https://i.imgur.com/1Qcgirt.png)

**Pushing your code files**

This the last step where we will be running a command to push all our files to the remote repository from the **local** Git repository.

- [ ] use the command `git push -u origin master`, this will push all your files from your **local repository** to the master branch of the GitHub repository created.


## Conclusion

**Yay! There you have all your precious code files in your GitHub, safe & sound.**


Please share your **valuable feedback** on this article in the comment section below and can also **suggest** some changes for future topics as well!😇