Skip to main content

Clean up branches from your Git remotes

Project description

A command-line tool that helps you clean up Git branches that have been merged into master.

One of the best features of Git is cheap branches. There are existing branching models like GitHub Flow and Vincent Driessen’s git-flow that describe methods for using this feature.

The problem

Your master branch is typically where all your code lands. All features branches are meant to be short-lived and merged into master once they are completed.

As time marches on, you can build up a long list of branches that are no longer needed. They’ve been merged into master, what do we do with them now?

The answer

Using git-sweep3 you can safely remove remote branches that have been merged into master.

To install it run:

pip install git-sweep3

Try it for yourself (safely)

To see a list of branches that git-sweep detects are merged into your master branch:

You need to have your Git repository as your current working directory.

$ cd myrepo

The preview command doesn’t make any changes to your repo.

$ git-sweep preview
Fetching from the remote
These branches have been merged into master:

  branch1
  branch2
  branch3
  branch4
  branch5

To delete them, run again with `git-sweep cleanup`

If you are happy with the list, you can run the command that deletes these branches from the remote, cleanup:

$ git-sweep cleanup
Fetching from the remote
These branches have been merged into master:

  branch1
  branch2
  branch3
  branch4
  branch5

Delete these branches? (y/n) y
  deleting branch1 (done)
  deleting branch2 (done)
  deleting branch3 (done)
  deleting branch4 (done)
  deleting branch5 (done)

All done!

Tell everyone to run `git fetch --prune` to sync with this remote.
(you don't have to, yours is synced)

Note: this can take a little time, it’s talking over the tubes to the remote.

You can also give it a different name for your remote and master branches.

$ git-sweep preview --master=develop --origin=github
...

Tell it to skip the git fetch that it does by default.

$ git-sweep preview --nofetch
These branches have been merged into master:

  branch1

To delete them, run again with `git-sweep cleanup --nofetch`

Make it skip certain branches.

$ git-sweep preview --skip=develop
Fetching from the remote
These branches have been merged into master:

  important-upgrade
  upgrade-libs
  derp-removal

To delete them, run again with `git-sweep cleanup --skip=develop`

Once git-sweep finds the branches, you’ll be asked to confirm that you wish to delete them.

Delete these branches? (y/n)

You can use the --force option to bypass this and start deleting immediately.

$ git-sweep cleanup --skip=develop --force
Fetching from the remote
These branches have been merged into master:

  important-upgrade
  upgrade-libs
  derp-removal

  deleting important-upgrade (done)
  deleting upgrade-libs (done)
  deleting derp-removal (done)

All done!

Tell everyone to run `git fetch --prune` to sync with this remote.
(you don't have to, yours is synced)

Deleting local branches

You can also clean up local branches by using simple hack:

$ cd myrepo
$ git remote add local $(pwd)
$ git-sweep cleanup --origin=local

Development

git-sweep uses git-flow for development and release cylces. If you want to hack on this with us, fork the project and put a pull request into the develop branch when you get done.

To run the tests, this command:

$ git clone https://github.com/talhajunaidd/git-sweep3
$ cd git-sweep
$ poetry install
...
$ poetry run tox

Requirements

  • Git >= 1.7

  • Python >= 3.7 < 3.10.0

License

Friendly neighborhood MIT license.

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-sweep3-0.2.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

git_sweep3-0.2.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file git-sweep3-0.2.0.tar.gz.

File metadata

  • Download URL: git-sweep3-0.2.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0a2 CPython/3.9.5 Linux/5.13.0-7620-generic

File hashes

Hashes for git-sweep3-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ecb991461ef30eb1cc271f91ba7369bc0c85dc8b6a5c587c46471bcdaf51404b
MD5 d91444e98eec9469511e9bd5bf523c10
BLAKE2b-256 1ceb4c0a52e87040e95eb0dfbb0e45392afbb52ab3a2414bf520e0225d615365

See more details on using hashes here.

File details

Details for the file git_sweep3-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: git_sweep3-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0a2 CPython/3.9.5 Linux/5.13.0-7620-generic

File hashes

Hashes for git_sweep3-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae0ba15f851a5226fdfaa27ffcd0bfb47753f8b5b591664d56b3b8292e390041
MD5 648ca38f1eded53176ac1f3e6524c48b
BLAKE2b-256 2eb8d3af709c18d384f87c943cea554196c48fb3cc17a25ee968b8c99f42f6e4

See more details on using hashes here.

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