Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Sync With Remote Repositories

Ben edited this page Jul 1, 2021 · 2 revisions

in order to host projects using Github and to display the generated pages using the Github Page, it is necessary to synchronise the local project with the remote Github repository.

  1. follow the instructions below to create a repository on Github

create new github repo

  1. add a remote repository to a local project. When you create a repository on Github, the page will jump to the repository's home page, where the code under ...or push an existing repository from the command line is the command to connect your local repository to that Github repository.

add remote repo

  • open your local project folder using the VS Code editor 📁 two-dishes-one-fish

  • click (menu bar) View(V) -> Terminal to open the terminal (or use the shortcut Ctrl+`)

  • add a remote repository to your local project by entering the following command in the terminal (where [username] is your Github user name and [repo] is the name of the new repository)

    git remote add origin https://github.com/[username]/[repo].git

    ⚠️ since the local project was created based on the template two-dishes-on-fish downloaded from Github, the local project was already connected to this template's Github remote repository. If you enter the above command directly, it will not work, and will output an error message fatal: remote origin already exists. indicating that a remote repository named origin already exists, so you need to remove the existing remote repository first by entering the following command in the terminal git remote remove origin, and then enter the above command to execute it successfully.

    💡 You can see which remote repositories are connected to your project by typing git remote -v in the terminal.

  • create a branch called main for the local project by entering the following command in the terminal

    git branch -M main
  1. synchronise with the remote repository. Synchronise the local project code to the remote repository by entering the following command in the terminal
git push -u origin main

💡 the first two steps only need to be configured once, whereas this step is a synchronization of the local project with the remote repository, and should be performed once every version control finished, it means every time the state of the project is saved should excute the step 3. And since you have already set up the branch to be synced this time, you can use the more concise command git push for the next sync.