You are currently viewing How to create a main branch and push code in git

How to create a main branch and push code in git

First, create a new repository from GitHub. Then go to git bash terminal in windows. If you have not logged in you can refer to this post. After you have logged in to GitHub type these command to create a main branch and add the code to your repository.

First go to the code folder which you want upload to GitHub and type the following command to initialize the git to your code.

git init
git add .

Commit the your code

git commit -m "first commit"

Create a main branch with this command

git branch -M main
git remote add origin https://github.com/your_username/your_repository.git

Push your code to the main branch

git push -u origin main

Check your repository in Github you can see your code there.

Leave a Reply