-
Notifications
You must be signed in to change notification settings - Fork 2
Sync With Remote Repositories
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.
- follow the instructions below to create a repository on Github
- 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.
-
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 shortcutCtrl+`
) -
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 templatetwo-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 messagefatal: remote origin already exists.
indicating that a remote repository namedorigin
already exists, so you need to remove the existing remote repository first by entering the following command in the terminalgit 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 terminalgit branch -M main
- 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.