Skip to main content

Connect to git repository and delete branches which are not in remote repository from local repository

Project description

GitBranchCleaner

GitBranchCleaner is a tool to clean up git repositories. This tool allows users to delete branches from a local git repository that are not present in the remote repository. This tool is useful when you have a lot of branches in your local repository, and you want to clean up your local repository. This tool is not intended to delete remote branches as it is not safe to do so and one might need to do a lot of manual work to recover from such a mistake.

Installation

To use the tool first install using pip or git clone the repository and run the setup.py file:

pip install git-branch-cleaner

or

git clone https://github.com/Vishnu-Naik/git-branch-cleaner
cd git-branch-cleaner
python setup.py install

Usage

This tool can be used as a command line tool or as a library. Let's see those two options in detail.

Command Line Tool

The command line tool can be used to delete branches from a local repository that are not present in the remote repository. The command line tool can be used as follows:

repo_cleaner --repo <path to git repository>

--repo is the optional flag to the command. If this flag is not provided, the current working directory is assumed to be the git repository. The tool will show the branches that are on local and remote. As shown below:

=================================================
List of remote branches:
main
develop
feature/branch1
=================================================
List of local branches:
main
develop
feature/branch1
feature/branch2
=================================================

The tool will ask the user if they want to delete the branches that are not present in the remote repository. If the user enters anything else other than Y or y, the tool will end its execution. Else it will display the branches that are not present in the remote repository one after the other which are going to be deleted and ask for confirmation before deleting each of the branches.

Library

To use this tool as a library, you can import the GitRepoCleaner class from the git_repo_cleaner module and use it as follows:

from cleaner import git_repo_cleaner

from cleaner import git_repo_cleaner

git_repo_cleaner.main('/home/username/git_repos/dummy_project')

For finer functionality, you can use the GitRepoCleaner class directly as follows:

from cleaner.git_repo_cleaner import *

local_branches, remote_branches = GitRepoCleaner.get_local_and_remote_branches()
print(local_branches)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git-branch-cleaner-1.2.0.tar.gz (10.8 kB view hashes)

Uploaded Source

Built Distribution

git_branch_cleaner-1.2.0-py3-none-any.whl (10.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page