How to push code to a github repository ?

How to push code to a github repository ?

ยท

2 min read

Steps to Push code to Github ->

  • Create a new repository on Github

image.png

  • After creating repository on github , move to linux or git bash.

  • Move into that folder where files are present.

image.png

  • Now initialize the folder with git init to make it a git repository.
git init

image.png

  • Add changes in local repository . If you made any changes then first you have to add these changes in the local repository and stage them for the commit. Below command will help you to do it.
git add .

image.png

  • Commit the changes and prepare it for the remote repository so we can push it . Consider the command given below.
git commit -m "first commit"

image.png

  • Add remote origin. Type the below command.
git remote add origin https://github.com/username/repositoryname.git

image.png

  • At last, execute the command below to push the changes in remote repository.
git push -u origin main
  • If the above mentioned command does not work , try the below given command It will ask for the username and password ,
git push origin main --force
  • Enter github username
  • For password -> follow the steps

-> Go to Settings >> Developer Settings >> Personal Access Token >> Generate New Token >> Copy the new token and paste it in password

image.png

image.png

Did you find this article valuable?

Support Sayam by becoming a sponsor. Any amount is appreciated!

ย