Add an existing local project to GitHub

Use your browser to navigate GitHub, create a new repository in your account. Go to terminal and cd into project directory.

  • git init -b main #Initialize
  • git add . #add all files to staging
  • git commit -m "First commit" #commit locally
  • git remote add origin < repo_url > #Add url of remote repo, get url from github repo created
  • git remote -v #verify you have added the remote repo
  • git push -u origin main #push

Clone a project on GitHub

  • Navigate to local directory and create a folder for project and cd into.
  • Copy HTTPS url from project in GitHub.
  • git clone < url > . #don't forget the dot, which means 'here'
  • Enter username, and token (you will need to copy/paste this from Settings).

Useful Commands

    • git ls-tree --full-tree --name-only -r HEAD #list files being tracked
    • git branch #list branches
    • git checkout branch_name
    • git rm --cached filepath #remove a file from git tracking

References