Upload your project in Github

Upload your project in Github
Play this article

Table of contents

No heading

No headings in the article.

Github is a popular platform for version control and collaboration in software development. It allows developers to store their code remotely, track changes and collaborate with others. In this blog, we will go through the steps of pushing a local repository to Github from scratch.

Step 1: Create a Github Account

To start, you need to create a Github account. Go to Github.com and sign up for a free account. Once you have created your account, you will be taken to the dashboard.

Step 2: Create a Repository

A repository is a place where you can store your code and track changes. To create a repository, click on the “+” sign in the upper right corner of the screen and select “New repository”.

Give your repository a name, a description, and select whether it should be public or private.

I created a repository named "sample-project" to work on. We will use this example to follow the tutorial.

After clicking Create repository you will redirect to a page like this:-

Here is a link https://github.com/shamnad-sherief/sample-project.git in HTTP can be seen on the page that shows the link to your repository. We can call the link remote-URL where you push your code.

Step 3: Install Git

Git is a version control system that is used to manage code changes. To use Github, you need to have Git installed on your computer. If you do not have Git installed, you can download it from the official website.

Step 4: Configure Git

Before you start using Git, you need to configure it with your name and email address. This information will be attached to your commits and will help others to identify who made the changes. To configure Git, run the following commands in your terminal:

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

Step 5: Initialize Git in Your Project

To start using Git in your project, you need to initialize a Git repository. Open your terminal and navigate to the root directory of your project. Run the following command to initialize a Git repository:

git init

Note:- You should run this command inside your project directory

Step 6: Add Files to the Repository

Once you have initialized a Git repository, you can start adding files to it. To add all the files to include in your next commit, run the following command:

git add --all

Step 7: Commit Changes

Committing changes in Git means that you are taking a snapshot of your code at a particular point in time. To commit your changes, run the following command:

git commit -m "Initial commit"

The command will make a commit with the provided message including the files which you added earlier.

Step 8: Connect Your Local Repository to Github

At this point, your git changes are only in the local repository and github has no connection. To connect your local repository to Github, you need to add a remote repository URL. A remote repository is a version of your code that is stored on a remote server, in this case, Github. To add a remote repository, run the following command:

git remote add <your remote name>  <your remote URL>

Replace <your remote URL> with your URL which got after creating the repository. You can add any name in <your remote name> .

eg:- git remote add origin https://github.com/shamnad-sherief/sample-project.git

Here origin is my remote name. The remote name origin refers to a repository. If you are confused or getting any errors, you can follow the below page to get the right information,

Step 9: Push Changes to Github

Finally, to push your changes to Github, run the following command:

git push origin master

This will push your local changes to the remote repository on Github.

origin is the remote name

master is your branch name. By default master or main can be your branch name.

If you get any errors like this:-

error: src refspec master does not match any error: failed to push some refs to 'https://github.com/shamnad-sherief/sample-project.git'

It happens when your branch name is not master. To find your branch name:-

git branch

The above command will print your branch name and you need to update your branch name with the push command.

eg: git push origin <your branch name>

if your error is like this:-

remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed for 'https://github.com/shamnad-sherief/sample-project.git'

This error message indicates that you are trying to use a Git client that still supports password authentication, but the Git server you are connecting (Github) has disabled this method of authentication. To resolve this issue, you should switch to using a personal access token (PAT) or an SSH key-based authentication instead.

Refresh your Github page and see the changes:-

Pushing to Github is a simple process that involves creating a Github account, creating a repository, installing Git, initializing a Git repository, adding files, committing changes, connecting your local repository to Github, and finally pushing changes to Github. By following these steps, you can easily store your code on Github and start collaborating with others.

Did you find this article valuable?

Support shamnad sherief by becoming a sponsor. Any amount is appreciated!