Synchronize your local repository with a remote repository in Git
This article outlines the process of syncing your local repository with a remote repository. We will also see how to sync a GitHub branch with a remote repository on the command line.
Synchronize your local repository with a remote repository in Git
Suppose we have a local repository and an upstream repository and want to synchronize the two. How do we do that?
If you are not sure how to add the upstream repository to your local repository, follow the steps below.
You can check the configured remote repository using the command below.
$ git remote -v
origin https://github.com/Wachira11ke/Delftscopetech.git (fetch)
origin https://github.com/Wachira11ke/Delftscopetech.git (push)
To configure upstream, run:
$ git add upstream <URL for the original upstream repo>
We can now pull from upstream using the following command.
$ git pull upstream --prune
--prune
option will remove remote tracking branches that no longer exist in the remote. This will merge the changes into your current branch.
If you are not syncing with upstream but with the GitHub repository, run:
git fetch origin
git reset --hard origin/master
git clean -f -d
Your local branches should be exact copies of your remote branches (commits and files).
If you want to merge into your local master branch, make sure it is checked out before pulling.
We can now update our GitHub branch by running:
$ git push
In summary, you can easily synchronize your local repository with a remote repository. Add --prune
the -d remote-tracking-branches flag to remove remote-tracking branches from your local repository that no longer exist in the remote.
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
Changing drives in Git Bash
Publish Date:2025/03/30 Views:56 Category:Git
-
This short article will discuss how we can use Git Bash to have a Unix-style command line environment in Windows operating system and run multiple commands in this terminal. Git Bash Git is a collection of command-line utilities created to
Adding a remote branch in Git
Publish Date:2025/03/30 Views:142 Category:Git
-
Git does not allow its developers to create new branches on remote repositories. But instead, we can push an already existing local branch, and after doing so, we can bring it to the remote repository using some Git commands. In every versi
Creating and using branches in Git
Publish Date:2025/03/30 Views:99 Category:Git
-
This article introduces Git branches. We will see how Git branches can help you organize your projects. Some of the commands we will deal with are git branch and git checkout . git branch Use commands to create, display, and delete branches
Git force pull
Publish Date:2025/03/29 Views:166 Category:Git
-
In this tutorial, we will learn how to force pull changes from a remote repository in Git. Sometimes, we may need to discard local modifications and replace them with updates from a remote repository in a collaborative development environme
Git pulls Master into the branch
Publish Date:2025/03/29 Views:193 Category:Git
-
When developing software using the Git tool, you can create different branches for different features. When you make changes to master, these changes are not automatically added to other branches. This article will explain how to pull all t
Installing Git in Cygwin
Publish Date:2025/03/29 Views:116 Category:Git
-
Git is considered an active, innovative and highly recommended distributed version control system with a fantastic standalone command line while providing us with advanced features and complete internal methods. What is Cygwin Cygwin is con
Displaying remote repository information in Git
Publish Date:2025/03/29 Views:140 Category:Git
-
This tutorial is about displaying information about remote repositories in Git. We use Git, a version control system, to track changes made to files in our project directories through Git repositories. Usually, local repositories are tracke
Deleting a remote repository in Git
Publish Date:2025/03/29 Views:131 Category:Git
-
When we commit the wrong data to the origin, push it to the origin and merge it to the current branch. But later we realize that we don't need to do the merge in that repo, so the question here is how to undo or revert the merge commit that
Setting up a Git remote repository
Publish Date:2025/03/29 Views:78 Category:Git
-
This article will explain how to add or delete remote repositories. A remote repository is a project hosted somewhere, such as Github/Gitlab. Adding a remote repository allows us to use a short name (alias) to execute commands instead of ty