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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file git-branch-cleaner-1.2.0.tar.gz.

File metadata

  • Download URL: git-branch-cleaner-1.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for git-branch-cleaner-1.2.0.tar.gz
Algorithm Hash digest
SHA256 da86f08dd92a5c5611935f472cc49bb829447edd148ec53045a4fae51bb48a6e
MD5 590e10977f06714f7557bf41750b2c7c
BLAKE2b-256 8046a0e8c32e6aa9e5a9b61084ebd4113388b3e4beaa5644a0a1e90c0d185e6e

See more details on using hashes here.

File details

Details for the file git_branch_cleaner-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for git_branch_cleaner-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d4dd42d77f53904d2cad3993a886e4223005b1a1d6e9f57628d8fffb47f1a0b
MD5 92fac35afe055b5772b11c3d299e2c3b
BLAKE2b-256 0733f7aa58a19cb4f8d707a43d758150439bfaf29f23419b5ab3b9239111d2e7

See more details on using hashes here.

Supported by

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