• Skip to main content
  • Skip to after header navigation
  • Skip to site footer

Free-Mail

  • Events
  • Images
    • Instagram Goodness
  • Music
  • News
  • Software

Delete the local reference to a remote branch in Git

Delete the local reference to a remote branch in Git: Delete the local reference to a remote branch in Git Agil Antony Fri, 08/05/2022 – 03:00

Register or Login to like
Register or Login to like

After you merge a GitLab or GitHub pull request, you usually delete the topic branch in the remote repository to maintain repository hygiene. However, this action deletes the topic branch only in the remote repository. Your local Git repository also benefits from routine cleanup.

To synchronize the information in your local repository with the remote repository, you can execute the git prune command to delete the local reference to a remote branch in your local repository.

More on Git
What is Git?
Git cheat sheet
Markdown cheat sheet
New Git articles

Follow these three simple steps:

1. Checkout the central branch of your repository (such as main or master)

 $   git checkout <central_branch_name>

2. List all the remote and local branches

 $   git branch -a

Example output:

 
  4.10.z
* master
  remotes/mydata/4.9-stage
  remotes/mydata/4.9.z
  remotes/mydata/test-branch

In this example, test-branch is the name of the topic branch that you deleted in the remote repository.

3. Delete the local reference to the remote branch

First, list all the branches that you can delete or prune on your local repository:

 $   git remote prune origin --dry-run

Example output:

 
Pruning origin
URL: git@example.com:myorg/mydata-4.10.git
* [would prune] origin/test-branch

Next, prune the local reference to the remote branch:

 $   git remote prune origin

Example output:

 
Pruning origin
URL: git@example.com:myorg/mydata-4.10.git
* [pruned] origin/test-branch

That’s it!

Maintaining your Git repository

Keeping your Git repository tidy may not seem urgent at first, but the more a repository grows, the more important it becomes to prune unnecessary data. Don’t slow yourself down by forcing yourself to sift through data you no longer need.

Regularly deleting local references to remote branches is a good practice for maintaining a usable Git repository.

Follow a few simple steps to keep your Git repository tidy.

A diagram of a branching process
Image by:

Opensource.com

Git

What to read next
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.
Register or Login to post a comment.

: Opensource.com Agil Antony

Supporting Open Source.

Have you tried: Sailing in Africa ?

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Pinterest (Opens in new window) Pinterest
  • Email a link to a friend (Opens in new window) Email
  • More
  • Share on Tumblr (Opens in new window) Tumblr
  • Print (Opens in new window) Print
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
Published on 5 August 2022 by Alan Category: SoftwareTag: Branch, delete, Local, Reference, Remote

S8UL Makes History at the Esports Awards 2025, Becomes First Indian Organisation to Win Two Major Honours

Reading Time: 3 minutes S8UL wins Esports Content Group of the Year for the fourth time, Animesh …

Read moreS8UL Makes History at the Esports Awards 2025, Becomes First Indian Organisation to Win Two Major Honours

Trending Now: Atalanta vs Lazio

These are the latest trending searches on Google right now: Atalanta vs Lazio: : Daily Search Trends …

Read moreTrending Now: Atalanta vs Lazio

These Shoes Are Made For Strolling… Bummel Style

They say you should not judge a man until you have walked a mile in his shoes. And sometimes, if …

Read moreThese Shoes Are Made For Strolling… Bummel Style

About Alan

Previous Post:Nice Left Coast Shoreline photo
Next Post:Trending Now: Benni Mccarthy Wife

Reach Trust

Reach Trust is a holding trust for a number of companies within the Stratlec Group.

Copyright © 2026 · Free-Mail · All Rights Reserved · Powered by Straton Electrical

Back to top