Assumptions

  • You have a GitHub account
  • You have a project on your local computer you want to add to your GitHub
  • You are working on a Mac

Steps

  • Create a repository on GitHub
To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub. —GitHub Help
  • Run these commands in your terminal
cd YourProjectFolderName
git init 
git add .
git commit -m "first commit" # -m <msg> flag
git remote add origin https://github.com/YourGithubUsername/RepositoryName.git 
git push -u origin master # -u[<mode>] flag (untracked files)

If you’re using HTTPS, your command will look like https://github.com/YourGithubUsername/RepositoryName.git.

If you’re using SSH, it will look like git@github.com:YourGithubUsername/RepositoryName.git.

If the push command fails, it might be caused by a change in your remote repository after the init command eg. you added a README. Try the following command git push —f origin master as your last command. Be cautious. This is the only time I would ever recommend using the --force command. Find further details here.

Git's push --force is destructive because it unconditionally overwrites the remote repository with whatever you have locally —Atlassian Developer

References

GitHub Help
Atlassian Developer