Push Local Git Repository to GitHub | How to push local git repository to GitHub
How to push local git repository to GitHub with git-bash command
If you are a software engineer or a web developer or a related job holder then you must know about git. Git is a version controller.
Today I will discuss how to push the local git repository to GitHub very easily. So let's start.
![]() |
| Push local git repository to GitHub |
Git: https://git-scm.com/
GitHub: https://github.com/
You must need to install the git on your machine.
As you want to push your local git repository to GitHub then I assumed that you already created a folder in your hard drive and it contains some files although it is not mandatory to have files. To push your local git repository to GitHub, firstly you have to go to GitHub (https://www.github.com) and create an account. If you already have an account then no need to create an account. You can continue with your existing account. After login into your GitHub account, on the right top corner, click on the profile icon. Then from the dropdown menu click on the "Your repositories" option. Then a new window will open. Here on the page, you will find a green color "New" button. Click on the button. Then give your repository name. I will recommend keeping your repository name in lowercase. You can add a description but it is optional. By default your repository is public. You can change it to private if you want. A private repository means no one can see your repository without you. Then click on the "Create repository" button at the bottom. Then a new page will open. On this page, you will see some git bash commands. Just follow the command.
The commands for pushing local git repository to GitHub are:
echo "# test" >> README.md
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/satroyofficial/test.git
git push -u origin main
Just copy the commands respectively and paste them to your git terminal. git terminal must be opened to the folder that you want to push to GitHub.
Now I am going to describe the above commands:
The first command "echo "# test" >> README.md" is for creating a README.md file which is your project description. You can skip this command if you don't want to create a description for your project.
The second command is "git init" and it is the most important one. This command will initialize a local git repository in your hard drive.
The third one is "git add ." This will stage your all created or changed files.
The fourth command is "git commit -m "First commit". It will commit your changes. This means, in your code, what you have changes you can indicate with a message.
The fifth one is "git branch -M main". It will convert your local master git repository to the main repository.
The sixth one is "git remote add origin https://github.com/satroyofficial/test.git". This command is mots important one. This will connect your local git repository to the GitHub repository.
The final command is "git push -u origin main". This will push your local git repository to GitHub.
After successfully completing these commands go to your GitHub repository and boom! You will see all of your local git repository files to GitHub.
Here is the video tutorial link:







