Sometimes you might start working on a project and have git setup locally, but have not linked it to a remote repository. Here’s how to do that:

At the command prompt, switch into the project directory that you want to push to the remote repo and type git remote add origin (URL to the remote repo) (excluding brackets).

When you want to push your code to the remote repoistory, do the following:

git push -u origin master

NOTE: This will push your code to the master branch of the repository.

If you want to push your code to a branch other than master, create the branch on the remote repository and then type the following:

git fetch && git checkout nameOfBranch

Once you you have successfully completed the previous step, tell git which files you want to push by typing git add nameOfFiles and then commit your code using git commit (see a previous blog post of mine on how to set the default text editor for git CLI).

After committing your code, type git push -u origin nameOfBranch.