How to Git Refresh Remote Branches

Abdul Jabbar Feb 02, 2024
How to Git Refresh Remote Branches

Git is considered the most accurate and is the most in-demand software used by developers for their projects and can be operated by multiple developers simultaneously. It provides developers with many unique and eccentric features that are very difficult to handle but distinctive from other software in the technology field.

It is mainly popular for handling data because it also saves deleted data that are not in use. We can also find our deleted commits and valuable data when needed until it’s pruned from the repository.

We can say that Git will take care of our stale data that we don’t need anymore. References to remote branches are also left even after they are deleted using the command line.

If our project mate deletes some branch on our shared repository, it will still be available at our side until we forcefully edify it to be removed through Git commands.

In this article, we will learn to clean up our repository through the prune option in Git.

Update Local Branches in Git

While working with Git, we often want to update our local branch from the remote branch, which keeps our work with our teammates updated.

View Git Branches in Git

For viewing all the Git branches, including the local and remote branches and the local or remote repository, we will execute the command mentioned below:

git branch -a

If someone removes the remote branches on the server, it will not affect the remote branches as the local Git repository will not get updated through the above command. We can update the local list of remote Git branches through the below-mentioned command.

git remote update origin --prune

We can also update the local list of remote branches by using the flag --prune with the commands git fetch and git pull every time.

git fetch --prune

Through git fetch, new commits are updated, which are added by other teammates in the remote repository. git fetch will not update our local branches.

git pull --prune

This command executes fetch and combines these fetched commits into the local branch. After downloading new commits from the remote repository, it immediately updates the local branch.

All local lists of remote branches on the server can be updated automatically without doing any long work through the below-mentioned Git command:

git config remote.origin.prune true
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Update