Git

How to Update Git Clone

In Git, developers clone the remote repository in their local system to work on the same codebase simultaneously. Every developer makes modifications to the locally cloned repository and then pushes those changes to the GitHub repository for others to see. However, it is necessary to update the Git clone regularly to ensure that everyone is working on the latest version of the project.

This blog will illustrate the method of updating the Git clone.

How to Update Git Clone?

To update the Git clone, try out the below-mentioned steps:

  • Navigate to the particular local repository and list its content.
  • Switch to the cloned repository and view its content and commit history.
  • Update cloned repository using the “git pull” command.
  • Ensure changes.

Step 1: Redirect to Local repository

First, switch to the desired local repository:

cd "C:\Git\Repo1"

Step 2: View Repository Content

Then, enter the below-listed command and list the current repository’s content:

ls

It can be seen that the current repository contains two files and one cloned repository:

Step 3: Navigate to Cloned Repository

Switch to the cloned Git repository using the below-provided command:

cd linuxRepo

Step 4: View Cloned Repository Content

Now, display the content of the cloned repository:

ls

In the below output, the content of the cloned repository can be seen:

Step 5: View Commit History

Next, run the given-provided command to view cloned repository’s Git log:

git log --oneline

It can be observed that the HEAD is pointing to the “851eee2” commit id:

Step 6: Update Cloned Repository

To update the cloned local repository, fetch and merge the changes of the remote repository, execute the below-listed command:

git pull

Step 7: Verify Changes

After that, view the Git log to verify whether the changes have been added to the locally cloned repository or not:

git log --oneline

As you can see, the HEAD is now pointing to the most recent commit of the remote repository and changes have been added to the cloned repository:

Step 8: View Updated Content

Lastly, list the content of cloned repository to view changes:

ls

It can be observed the content of the cloned repository has been updated successfully:

That was all about updating the Git clone.

Conclusion

To update the Git clone, first, navigate to the locally cloned repository. Then, view its content and commit history. Next, execute the “git pull” command to fetch and combine the content of the remote repository and update the cloned repository. Lastly, ensure changes by checking Git log. This blog illustrated the method of updating the Git clone.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.