How to upload your project on github: A Guide

Last Updated on 10 Aug 2021 by Ankur Gupta
10 mins read

In this tutorial, we'll be publishing our code on Github by creating a repository. A repository is a central location where your data and code will be stored. We'll be discussing about three ways we can do this- 

  • Directly using Github
  • Using Git command line
  • Using Visual Studio Code Github Extension

Creating a Github Account

First of all, we'll be beginning with how we can create a GitHub account. To do so, we can simple go to the website https://github.com. Then you click on Sign In or Sign Up depending upon whether you have an account or not, fill out some details and you can then see the Github Homepage.

Creating a Github Repository

Now, we'll need to create a Github Repository, at the topmost corner at the homepage https://github.com, you'll see a New Option, you can click on it to create a new Repository.

Afterwards, you'll be prompted to add a Repository name which can be any name of your choice, whether you want to create a public or a private repository, you can also add a Readme, a gitignore files (which is just a text file containing files and folders you don't want git to push) and a license. All the these details are optional and you can use them according to your need. You can then click on Create Repository and your repository will be created.

Pushing Code in Github Repository

1. Using Github

We can directly upload files in github which is probably the most easist way if you're working on an small project which does not require much further changes.

Under your repository like https://github.com/semikolan-dev/blog.semikolan.co, you'll see an Add Files option -> Upload Files or create new file if you directly want to copy paste your code or write directly.

Now you can select files, write any comments with a commit message and press on Commit changes to make your changes live. You can also create a new branch and push your code in that branch.

2. Using Git CMD

You can also clone your Github Repository and push changes from your local system to Github. First of all, you'll need to install Git, you can download it through https://git-scm.com/downloads. You can then install Git and open Git CLI or any other terminal depending upon your operating system. Here's how my windows terminal looks like in Windows 11:

You can now go to your Github Repository and copy the .git path through which you can clone your repo, here is a screenshot of how you can copy the HTTPS link:

Now you can go to the Git Terminal and clone the repository using:

git clone yourcopiedlink.git

Now you can open your repository in your system, make the necessary changes and change the folder directories according to your needs. 

After you're done with all your changes, you can then add the changes and commit them to your github repository using the following commands in your Git Terminal:

cd your_repo_name
git add .
git commit -m "Any commit message here"

You can then push these changes in your Github Repository using:

git push origin main

Note that we're not going into branches in this tutorial and hence we're using the "main" branch which is the default branch used by Github.

Now your changes will be pushed in your repository. This method is not only specific to Github and can be used in Heroku and other sources too which uses Git.

If you're using a Linux based Operating System, you may also need to use sudo before using some of these commands.

3. Using Visual Studio Code

The source control in VS Code can also be helpful and make your process of pushing the code to Github even more easier. 

You can see this source control tab in your VS Code. 

First of all, we can clone a Github Repo by pressing F1 -> Searching for clone and selecting Git: Clone option. We can now paste the link we copied from Github containing the .git file of our repository. The link can be found in your Github Repository page which looks like

You can also connect your Github Account and can directly choose the clone for Github option to clone a repository directly even without using the link.

Now you can open your repository folder using VS Code and make the necessary changes. After making all the changes, you can then see your changes in the source control panel like below:

Here U means the creation of a new file, M means modification of an existing file and A means removal of a file. You can then stage all your changes by pressing the + icon which you can see by hovering on the Changes. 

You will see the your changes are staged as:

You can also type a commit message as I've written above. To commit your changes, you can now press the tickmark near the place where source control is written. Your changes will be then commited. Now we just need to push the changes which can then be done by clicking on the more option (the ... three dots) and clicking on push. 

If you're doing this for the first time, you may also need to login using Github and authorize VS Code to push codes from your behalf.

 

Category: Github | Technology

Relavent Tags: Github, Version Control, Git