How to Push Code to Github
Tags: programming, beginners, productivity, codenewbie
Published: 2022-03-17 20:16:35

GitHub is a provider of internet hosting for software development and version control using Git. It is also a publishing tool and a great way to collaborate with others. Github gives us the ability to save our process and go back to earlier points as needed.
 
We can push code to Github following these steps;
Before we can push code to Github, Git needs to to be installed on your computer, start by heading to the Git website and downloading the latest version. Follow the steps provided on the website and install Git on your computer.

After installing Git, open Github and confirm that you are signed in, click on Create new repository and then add a name and description

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5p3d76ipsgul92kpbpz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi6agwk786sbiepesv5i.png)

After creating a new repository, a quick setup page is loaded which has important information on how to push your code to the repository using the terminal 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kk8l9fo9j9nvajdhzwa9.png)

Next open the terminal and set your local project as the working directory by typing `cd` followed by the path of the folder where your project is saved on your computer and hitting return. The files in the directory can be viewed by typing `ls` and hitting return. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kv01tjnhmrkzhcikhg3n.png)

Intialize your local directory as a git repository by typing `git init` and hitting return

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0awczhe3wjgbei3y5as1.png)

Add the files in your local repository to the git repository by typing `git add .` and hitting return.This stages the files for  commit. Typing `git status` and hitting return shows us the files  that have been staged to commit

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxx2rz4lwhat06ije39q.png)

Commit the files you have staged  by typing `git commit -m “first commit”` and hitting enter.The -m flag specifies what commit message will be recorded in the repository. This is purely informational to users. The message might be “fixed bug,” “new level,” etc. This message helps other developers easily know what changes have been made to the code.

Specifying the remote repository’s url comes next and to do this copy the url from the Github repository quick setup page then in terminal type `git remote add origin` , paste the Git repository’s url and hit return.

Finally, push the code in your local repository by typing `git push -u origin master` and hit return. Enter your Github username and password  when requested. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nhy807nbird0wewq2n3.png)

Once all these steps are completed, the files from your local directory will be added to your repository on Github

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6f2sbep1wg3rqzyjs07.png)