If you have a project in your local machine/laptop and you want to push the code to GitHub, then follow the below steps:
Step 1:
Create a repository in GitHub. In order to create a repository in GitHub, you should have an account. If you don’t have a GitHub account, sign-up.
Login to GitHub, click on New button and fill the Create a new repository form. Enter repository name and mark the repository as Private if you don’t want it to be publicly accessible.
Step 2:
Once the GitHub repository is created, copy the repository url. Go to local project root directory, open a terminal and run the following commands in given sequence-
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/[user-name]/[repository-name].git
git push -u origin main
This will push your code to remote GitHub repository.
If you already have source code that is pointing to some other GitHub repository, and you want to push the code in your GitHub repository then follow the below steps-
git remote add origin https://github.com/[user-name]/[repository-name].git
git branch -M main
git push -u origin main
Now the code will point to your GitHub repository.