GitHub first time — Tutorial (2022 updated)

  1. Create a new repository on GitHub
  1. At your local computer , change the current working directory to your local project.
  2. Initialize the local directory as a Git repository:
    $ git init

3. Add the files in your new local repository. This stages them for the first commit.
$ git add .

4. Commit the files that you’ve staged in your local repository.
$ git commit -m "First commit"

5. Go to your github repository to get your repository’s URL

6. Setting Global Git Username and Email

git config --global "Your Name"
git config --global ""
  1. In the Command prompt, add the URL for the remote repository where your local repository will be pushed
    $ git remote add origin <remote repository URL>
    # Sets the new remote
    $ git remote -v
    # Verifies the new remote URL
  2. Push the changes in your local repository to GitHub if there is a remote branch called master (or main if that’s what you’re using)
    $ git push origin main
  3. if error while push like this
    ( ! [rejected] main -> main (fetch first)
    error: failed to push some refs to ‘’
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., ‘git pull …’) before pushing again.
    hint: See the ‘Note about fast-forwards’ in ‘git push — help’ for details.

that means you need to pull rebase first .

$git branch — set-upstream-to=origin/main main
$git pull — rebase

Now you can push to remote again :

$git push origin main

pushed successfully! You did it !

Error handling :

In case you input wrong origin , you can remove it then add a correct one :
check current git : git remote -v

you will see the output like this

“origin” is the name you need to remove it .

Now remove it by : git remote remove origin

Then re add a correct one.

if you encounter problem when you $git push origin main :
error: failed to push some refs to ‘’ , probably because your local git branch named ‘master’ but it is named ‘main’ on github.
If so , you should change local branch first before you push .

$git branch -m master main

If this is helpful for you , you can donate me a coffee :

APE : 0xf4E2c9701dF27F900ac594cAAfd87D1e733e2F18
BTC : 3Bf3b7eUeR2KEqrQtjagjzyp7ATiy8ZGcu
DOGE : DAPbRSk2Bmc1QPN8jr8zMe5V7wk8oURWJL
ETH : 0x659ede5a1d2332Fc126EBE00B4d2B7d32906b942
LUDAN : 0x165D6Af92FC63A25A9317B9d7C6E65e561A213D8

or if you are interested in more fun :