Git

How to Update Git Repo

Git is widely utilized for tracking project changes. This platform is primarily utilized for source code management in software development. It enables multiple developers to work together all over the globe. Git supports non-linear development through its multiple branches. Developers can add changes locally and then push them to the repository to update the project folders with the new changes.

In this guide, we will explain the method to update the Git repository. So, let’s start!

How to Update Git Repo?

To update the repository, first, we will clone the Git remote repository on Git local repository and then add an upstream remote with the given URL through the “$ git remote add upstream <remote-URL>” command. Next, fetch and download the content from Git remote repository using the “$ git pull upstream <branch>” command. It will instantly update the Git repository.

Now, let’s move ahead to understand the above-provided scenario!

Step 1: Copy Git Remote Repo URL

First, open the GitHub host service and go to the remote branch tab. Hit the “Code” button and copy its “HTTP” URL:

Step 2: Launch Git Bash

Next, open up the “Git Bash” utilizing the “Startup” menu:

Step 3: Clone Git Remote Repo

Clone the Git remote repository by specifying the copied remote repository URL in the following command:

$ git clone https://github.com/GitUser0422/demo_1.git

Step 4: Add Remote Repo

Now, add the upstream remote repository with the remote URL:

$ git remote add upstream https://github.com/GitUser0422/demo_1.git

Here, we have connected the upstream remote with our Git local repo:

Step 5: Update Git Repo

Next, run the “git pull” command with to update the Git repo:

$ git pull upstream master

The above command will fetch and download the content(remote branch) from the remote repository. In our case, our Git repo is already updated:

We have stated the procedure to update the Git repository.

Conclusion

To update the Git repository, first, execute the “$ git clone <repo-url>” to clone the Git remote repository. After that, add an upstream remote with the given URL by executing the “$ git remote add upstream <remote-URL>” command. Next, fetch and download the content from Git remote repository using the “$ git pull upstream <branch>” command, which immediately updates the Git local repo. This guide explained the method of updating the Git repository.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.