Giter Site home page Giter Site logo

boisde / git-cleanup-branches Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weirdgiraffe/git-cleanup-branches

0.0 1.0 0.0 9 KB

script to delete local git branches which were removed in remote or merged into current branch

License: MIT License

Python 100.00%

git-cleanup-branches's Introduction

git cleanup-branches

When you're working on some project for a while the amount of git branches is getting up, so it's getting hard to understand which branches are still useful and which were already merged and deleted from the remote. This script tries to address this problem by providing a simple, interactive experience to remove branches which were deleted at remote and those which were already merged.

This simple script will delete local branches which are:

  • deleted in remote (remote name could be set via --remote, by default origin)
  • merged into the current branch

The script is interactive and will ask before pruning the remote or deleting branches.

Note: you need python3 to be installed to run this script

Installation:

curl https://raw.githubusercontent.com/weirdgiraffe/git-cleanup-branches/master/git-cleanup-branches.py --output /usr/local/bin/git-cleanup-branches
chmod +x /usr/local/bin/git-cleanup-branches

Then open a new shell, go to a git repository and use it with git cleanup-branches.

examples

The script gives you a list of branches to be deleted and waits for confirmation:

$ git cleanup-branches
  prune: feature/a was deleted in origin. delete? (y/N): n
  prune: feature/b was deleted in origin. delete? (y/N): y
 merged: feature/c was already merged to master. delete? (y/N): n

local branches to keep:
- feature/a
- feature/c

local branches to delete:
- prune feature/b (prune origin)

if you will delete those branches you will
not be able to restore them from remote.
continue? (y/N): n

Script will warn you in case you want to keep local branches which were deleted from remote:

$ git cleanup-branches
  prune: feature/a was deleted in origin. delete? (y/N): n
  prune: feature/b was deleted in origin. delete? (y/N): y
 merged: feature/c was already merged to master. delete? (y/N): y

local branches to keep:
- feature/a

local branches to delete:
- prune feature/b (prune origin)
- prune feature/c (merged into master)

if you will delete those branches you will
not be able to restore them from remote.
continue? (y/N): y
Deleted branch feature/b (was 031b5b312).
Deleted branch feature/c (was ab120153e).

stale branches in origin are about to be pruned.
if you will press y now it would be impossible
to link your stale local branches to stale
remote branches in origin.

prune remote origin? (y/N): y
Pruning origin
URL: [email protected]:xxx.git
 * [pruned] origin/feature/a
 * [pruned] origin/feature/b

You can skip interactive selection by running with --all:

$ git cleanup-branches --all

local branches to delete:
- prune feature/b (prune origin)
- prune feature/b (prune origin)
- prune feature/c (merged into master)

if you will delete those branches you will
not be able to restore them from remote.
continue? (y/N): y
Deleted branch feature/a (was ce195b1ef).
Deleted branch feature/b (was 031b5b312).
Deleted branch feature/c (was ab120153e).
Pruning origin
URL: [email protected]:xxx.git
 * [pruned] origin/feature/a
 * [pruned] origin/feature/b

You can specify remote name (origin by default):

$ git cleanup-branches --remote foo --all

local branches to delete:
- prune feature/b (prune foo)
- prune feature/b (prune foo)
- prune feature/c (merged into master)

if you will delete those branches you will
not be able to restore them from remote.
continue? (y/N): y
Deleted branch feature/a (was ce195b1ef).
Deleted branch feature/b (was 031b5b312).
Deleted branch feature/c (was ab120153e).
Pruning foo
URL: [email protected]:xxx.git
 * [pruned] foo/feature/a
 * [pruned] foo/feature/b

git-cleanup-branches's People

Contributors

kmasubhani avatar weirdgiraffe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.