Skip to content

Instantly share code, notes, and snippets.

View krshnpatel's full-sized avatar
😄

Krishan Patel krshnpatel

😄
View GitHub Profile
@krshnpatel
krshnpatel / Git Sync Local Branches with Remote.md
Last active October 17, 2024 10:56
A simple script to help you sync your local branches with your remote branches.

Overview

Description

This script allows you to sync your local branches with your remote branches. It would detect any local branches that have been deleted on your remote repository. Any local branches that have not been pushed to remote will not be detected because they might be your "work in progress" branches.

NOTE: If you create a local branch, then push it to your remote repository, then you manually delete that branch on your remote repository. This script will detect that local branch. So I would suggest reading the list of branches marked for deletion before allowing this script to delete them.

Purpose

Usually it's a good practice to delete your remote branch after it has been merged to your default branch (i.e. main, master). However, this means that there will be several stale local branches and these will accumulate over time. Essentially, this script will help you delete those stale local branches which have been deleted on the remote repository.