Update Git clone
This article outlines the steps we can take to update our cloned repository in Git.
Suppose we have a remote repository on GitHub that we forked and cloned on our local machine. How can we update our cloned repository with the original remote repository?
Update Git clone
We previously forked from a GitHub public repository in the example below. After copying the repository to our personal GitHub account, we clone the repository to our local computer.
Now, we want to update our clone with the remote. How do we do that?
We will start by setting up the upstream repository. In simple terms, the upstream is the original repository that we forked from.
We have to go back to the original repository and copy the link to the repository.
To set up the upstream, we will run the following command:
$ git remote add upstream <URL>
Once completed, you can check whether the upstream exists using the command with a double verbose flag git remote
, like this:
If there are any changes in the original/central repository, we can git pull upstream
bring them to our local repository using the command.
You will have to include a branch to pull from. In our case, we only have one branch, master .
If we have other branches, we can specify which branch to pull from in the command.
To update our master we will run the following command:
$ git pull upstream master
This will fetch the changes and merge them into our master branch.
As shown above, Git will notify you if there are changes.
Finally, we can stage and commit our changes. If there are merge conflicts, you must manually resolve them and commit your changes.
The cycle doesn't end here. Updating branches in GitHub is a logical process.
This is done by pushing the committed changes. We will run the following command:
$ git push origin master
This will keep your forks and clones in sync with the original repository.
Summarize
In short, you can update your Git clone with a central repository by setting the upstream of your clone, after which you can pull any changes to your local repository.
Every time you are going to work on a project, it is always recommended to update your clone, especially when you are working on a joint project. This will ensure that you stay in sync with other developers.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Git shows remote tracking branches
Publish Date:2025/04/03 Views:125 Category:Git
-
Branches on remote Git repositories are called remote branches. These are pointers to our remote repositories, including branches, tags, etc. Local branches only exist on each developer's local personal computer, but there is only one remot
View merged and unmerged branches in Git
Publish Date:2025/04/03 Views:96 Category:Git
-
This article discusses how to list merged and unmerged branches in Git. Git branches encourage convergent evolution of code. This is where we create a branch as a temporary space to work on a feature, and then merge the branch with its orig
The difference between Fork and Branch on GitHub
Publish Date:2025/04/03 Views:157 Category:Git
-
This article discusses the difference between Form and Branch on GitHub. In the context of coding, the current era relies more on collaboration. GitHub is one of the most commonly used collaboration tools. Forking and branching on GitHub ar
How to determine the current branch in Git
Publish Date:2025/04/03 Views:164 Category:Git
-
Git is a unique and popular version control system that is used by most of the software developers to keep an eye on the changes made in various applications and stay connected with other teams on the running projects. It helps large teams
Difference between Git Merge Origin/Master and Git Pull
Publish Date:2025/04/03 Views:195 Category:Git
-
This article outlines the differences between the git merge origin/master and git pull commands. These two commands integrate changes from a remote repository into the current local branch. However, each command's operation is unique and ha
Git Pull Origin branch overwrites Master branch
Publish Date:2025/04/03 Views:143 Category:Git
-
This article explains how we can revert the changes made to the master git pull origin branch branch after running the command . Assume that you have a master branch and a feature branch in your local and remote repositories . You pull chan
Git Pull and Merge Commands
Publish Date:2025/04/03 Views:56 Category:Git
-
In the vast world of version control systems, Git is the only fast, well-organized, in-demand, and easily accessible version control system that enables users to work on various projects simultaneously in an efficient manner without any col
Difference between Git Checkout --Track Origin/Branch and Git Checkout -B Branch
Publish Date:2025/04/03 Views:185 Category:Git
-
This article outlines the difference between the git checkout -b branch origin/branch and git checkout --track origin/branch commands. We use these two commands to check out remote branches in a Git repository. These two commands have the s
Rolling back to an old commit in a public Git repository
Publish Date:2025/04/03 Views:115 Category:Git
-
This article explains how we can roll back a public Git repository to an old commit. When using Git version control, we can go back to any desired point. Without further ado, let’s get into today’s agenda. Rolling back to an old commit