Kaigai Blog living abroad in my twenties

【My Study Note】Remote vs. Local

Infotech Web Developer

Remote vs. Local


In this article, you will learn about pushing your changes from your local to a remote repository.

Remote refers to any other remote repository to which developers can push changes. This can be a centralized repository, such as one provided by Git hub, or repositories on other developer devices.

The remote code is accessed through a URI which is unique and only accessible to those who have permission.

Example

Let’s say we have a project called coding project one which is located on Git hub with a unique URL. In other words, this project is stored on a remote server. When a user wants to copy this project to their local device, they need to either perform a clone if it’s the first time or pull it to get the latest changes.

To clone a project a user must first choose a folder on their local machine. Coding project one is then cloned from the server and copied into the chosen folder. The user can then make changes to the project and push those changes back to the server.

Other users working on the code base won’t see those changes on their local machines unless they pull the latest changes from the server. One of the advantages of it is that you can work offline and then commit your changes when you are ready.

How to do it?

1. Create a new directory

mkdir my-repo

2. Change your current directry

cd my-repo

3. Creating your new repository

git init
// This returns like this
Initialized empty Git repository in root/projects/my-repo/.git/

This will return a line telling me that an empty repository has been initialized under route projects my-repo.

However, this is only you initialized a local repository which has no connection to a central repository that sits either on GitHub or another server

Right now it’s only available locally on your machine.

Using URI to connect

git remote add origin URI

Pull down changes from the repository

git pull

What I’m going to do next is use the Git pull command which will connect with the GITHub server, and pull down all the changes from the repository.

So on your local, you now have all the changes, but when you check the directory it’s blank. The reason for this is that you haven’t set up a branch that matches with what I have on the server repository.

Fortunately, you can change that by performing the command.

git checkout main

This will set up a branch main on your local that tracks the branch main from the remote.