Git support of managing local and remote repositories has contributed to making computing a better experience. The remote repositories are managed on the server, whereas local repos are maintained on the machine and can be accessed without internet availability. Git offers two streaming supports: one is upstream, and the other is downstream; the upstream refers to where you clone your rep, and downstream allows you to integrate your work with other works.

As Git is distributed version control software, working in a parallel manner may acquire the confusion state as there are several contributors making changes on a single project. Thus, it is recommended that the remote and local repositories must be synchronized to avoid any mishaps like you may require to fall back to some previous versions, which can be budget and time-consuming.

While working in an environment where sometimes you have to make changes on remote, and you want that same changes must be present on your local repository as well. Keeping in view the importance of synchronization, we have prepared this guide to demonstrate the steps of keeping the local repository the same as remote:

How to make local repository same as remote

This section lists down the steps to keep updating the local repository time by time; whenever the remote repository commits changes; one can follow the steps in this section to apply those changes in the local repository as well:

Step 1: Clone your remote repository to local

We are taking here a GitHub project as an example, and we want to clone that project to our machine. For this, follow the command mentioned below to clone the remote to the specified directory: (in your case, the link of the project will be different)

$ git clone https://github.com/marcusanth/Bat-inspired-test-case-prioritization.git

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/1-11.jpg" data-lazy- height="127" src="data:image/svg xml,” width=”726″>

Once the project is cloned; change the working directory of the terminal to the directory where you have cloned the project:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/2-11.jpg" data-lazy- height="103" src="data:image/svg xml,” width=”736″>

Note: If you have already cloned the project, you can jump directly to step 2.

Step 2: Add the upstream as a remote

In git projects, upstream refers to the repository from where you want to clone: This step adds a new remote from where the changes will be fetched and synchronized:

Firstly, check the list of available remotes by issuing the command mentioned below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/3-11.jpg" data-lazy- height="95" src="data:image/svg xml,” width=”931″>

It is observed from the output that only “origin” is present as a remote; you can add a new remote by issuing the command mentioned below: we have used this command to add “linuxhint” as a new remote:

$ git remote add linuxhint https://github.com/marcusanth/Bat-inspired-test-case-prioritization.git

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/4-10.jpg" data-lazy- height="175" src="data:image/svg xml,” width=”1027″>

The output in the image above shows that the new remote “linuxhint” is added successfully:

Step 3: Make origin same as “linuxhint” remote

This step will fetch the content from “linuxhint” and the changes will be matched with the “origin”: use the command mention below to perform the above-said action:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/5-10.jpg" data-lazy- height="138" src="data:image/svg xml,” width=”960″>

Step 4: Navigate to master branch and merge the linuxhint master

After fetching the content from the remote: you have to be on the master branch; in case you are not, you can use the following command to get to the master branch; in our case, we are already on it:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/6-10.jpg" data-lazy- height="94" src="data:image/svg xml,” width=”960″>

Afterwards, you have to merge the master branch of upstream remote (linuxhint in our case) by issuing the command mentioned below:

$ git merge linuxhint/master

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/7-6.jpg" data-lazy- height="78" src="data:image/svg xml,” width=”964″>

If you are maintaining local and remote repositories, then you must have performed steps 1 and step 2. The first two steps are one-time efforts; after that, you have to follow only step 3 and step 4 every time to fetch and merge the content.

Conclusion

Git has emerged as a top trending version control system in developing and maintaining large projects. The major distinction of Git is the tracking of version by time, ensuring the privacy of the data stored on the repositories, and providing online as well as offline access by creating remote and local repositories. However, it is also recommended to keep your local repository the same as remote; so that the content saved on both repositories remains the same. In this descriptive guide, we have provided a step-by-step procedure to synchronize the local repository same as the remote repository. Moreover, if any additions are performed on the local repository and that are not available on remote, those changes will be removed to keep the data the same.