JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Update local branch from remote in Git

Author:JIYIK Last Updated:2025/03/28 Views:

Git is a popular and well-known platform for developers and their development teams. It can be said that using Git is crucial as it has many unique features compared to other tools.

It is crucial for developers to understand how to handle its features, such as Git repositories and the corresponding pull and push functions.

We have faced various situations while using Git when we have to update our local branch from a remote branch so that we should be in sync with the current team work.


Remote branches in Git

Before we get into this topic, we should know a little bit about remote branches. Remote branches are branches that exist in remote repositories and can be accessed using some Git commands.

A remote tracking branch is a branch in your local repository that tracks a remote branch. This is the branch to which each team member commits work so that everyone can pull and maintain the latest local branch.


Updating feature branches in Git

Assuming our feature (local branch) is not up to date yet, now we have to fetch the changes from our master (remote) branch so that our local feature branch is updated from the latest updates.

First, we will update our master branch. To do this, we go to our local project and check out the branch we want to merge into the master branch.

We will run the following command.

$ git checkout master

We will get the remote branches by fetching the branches and their commits from the remote repository. The full form of option -p is --prune which is used to remove remote tracking references which do not exist in the remote.

Commits to master will be saved in the local branch: remotes/master/original .

$ git fetch -p origin

Now we will merge the changes we want from origin into our local branch. Our master branch will be synchronized with the remote repository without losing our local changes.

We will run the following command to merge the remote branch into local.

$ git merge origin/master

If some changes in the local master branch are not available in the remote origin/master branch, we will use here git pullin order to pull the latest changes.

git pullThe command will apply the merge and build a merge commit that incorporates these changes.

$ git pull

We will check out the branch we want to merge into.

$ git checkout <feature-branch>

We will now merge our master branch into our local feature branch so that it can be updated with the latest changes from our team.

$ git merge master

This method will only update our local feature branch. To update it on the remote branch, we will push the changes we made, and then all updated local changes will be pushed to the remote branch.

$ git push origin <feature-branch>

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.

Article URL:

Related Articles

Git authentication

Publish Date:2025/03/28 Views:163 Category:Git

This article demonstrates connecting a local repository to a remote repository on GitHub/Gitlab without getting 身份验证失败 error messages. Creating a local repository from scratch in Git To create a local repository from scratch, fo

Log graphs in Git

Publish Date:2025/03/28 Views:96 Category:Git

This article shows you how to use git log the command to graphically view the commit history in Git. Viewing log graphs in Git The command git log displays all the repository history at once snapshots(commits) . This command has a default f

Git refresh remote branch

Publish Date:2025/03/28 Views:93 Category:Git

Git is considered to be the most accurate and the most used software by developers in their projects and can be operated by multiple developers simultaneously. It provides many unique and quirky features to the developers which are very dif

Updating Git on Mac

Publish Date:2025/03/28 Views:181 Category:Git

When working on Git, you should stay updated with the latest version to get its latest features. This article will discuss how to install and update the latest version of Homebrew and Git on your personal computer. Homebrew on Mac Homebrew

Enable Git Tab Auto-Complete

Publish Date:2025/03/28 Views:109 Category:Git

This tutorial demonstrates how to enable git tab autocompletion. Importance of enabling Git Tab auto-completion When developers work with source code, they mostly prefer Git as it is a very familiar and convenient platform for developers th

Restoring a repository in Git

Publish Date:2025/03/28 Views:158 Category:Git

Sometimes while using Git, we come across a situation where we want to pull the latest changes from the remote repository and it conflicts with the existing modifications or files, then we have to push those files to the storage. Git provid

Undo Git Stash Pop conflicts

Publish Date:2025/03/28 Views:178 Category:Git

You can undo this using the solutions in this article git stash pop with merge conflicts . We show you how to abort an erroneous stash pop operation and return to a clean state. But we also demonstrated a git stash pop way to resolve the co

Resolving Git stash conflicts without committing

Publish Date:2025/03/28 Views:72 Category:Git

This article outlines the steps you should follow to resolve Git stash conflicts without reverting or creating commits. For a simpler context, we will simulate a situation where the git stash pop command results in a conflict and try to res

Git Stash needs to be merged

Publish Date:2025/03/28 Views:128 Category:Git

Git is a stylish platform that provides us with many features, one of the main ones is storage. With this unique feature, we can accumulate a lot of unchanged work that we don't want to commit to our repository when the code is checked in;

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial