how to connect git to github repository code example

Example 1: How to upload a files to a repository on github using gitbash

git init
git add .
git commit -m "message for the commit"
git remote add origin https://url-of-github-repo
git push origin master or git push -f origin master

Example 2: push code to github command line

git add .
git commit -m "message for the commit"
git remote add origin https://url-of-github-repo
git push origin master

Example 3: connect to github repository from terminal

to connect your repository from your terminal to your github requires you
1) Create a github repository than
2) Open Terminal
3) You will initilize git and make a branch with: git init -b main
3) Followed by the command: git add . - this adds all your edited work.
4) Followed by a Commit Command: git commit -m "this is my work" - used for 
merging
5) At the top of your GitHub repository's Quick Setup page, click  to
copy the remote repository URL.
6) In terminal add the repository URL where your local repository will be
pushed to: git remote add origin  <REMOTE_URL> - sets the new remote
7) git remote -v -Verifies the new remote URL
8) Push Changes in local Repository to GitHub: git push -u origin main -
Pushes the changes in your local repository up to the remote repository 
you specified as the origin

Example 4: how to set up git for github

$ git config --global user.name "Your name here"
$ git config --global user.email "[email protected]"

Example 5: create new repository on the command line

git init
git add README.MD
git commit -m "commit message"
git remote add origin git url_of_github_repo
git push origin master

Example 6: pushing to github

git add .
git commit -m "First commit"
git push origin master