deliciousinsights / git-clean-stale-local Goto Github PK
View Code? Open in Web Editor NEWCleans local, merged branches that still track obsolete remote refs
License: MIT License
Cleans local, merged branches that still track obsolete remote refs
License: MIT License
In some cases git will not know that a branch has been merged because your local version of the branch differs from the copy of the branch that was merged.
For example, let's say User A checked out Branch A, then User B checked out Branch A and rebased it to squash some of the commits into a larger commit, then User B merges Branch A into the default branch (let's say master
) and deletes Branch A from your GitHub/GitLab repo. git on User A's machine doesn't think Branch A was merged into master
because the commit SHA of the latest commit on User A's copy of Branch A doesn't match any of the commits that are now in master
.
Unfortunately I'm not sure of a good way to fix this issue, short of adding a flag that would let you delete any branches without upstream counterparts (this would have the side effect of deleting local branches you haven't pushed yet, which isn't great).
When I run the script on macOS, it fails with:
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
fatal: malformed object name
Could you maybe adopt it to macOS, as well?
@tdd Do you think that would be too dangerous to avoid unmerged stale branches cleanup?
git clean-stale-local [-n|--dry-run] [-u|--not-merged]
If our repository doesn't stick to the conventional origin
remote or has many remote repositories, we are not able to stale clean branches for theses ones.
We should be able to use both:
git clean-stale-local [-n|--dry-run]
(using origin
as default) or git clean-stale-local [-n|--dry-run] <remote name>
.
We may also consider adding a global option, targeting all remotes: git clean-stale-local [-n|--dry-run] [-a|--all]
I got stuck on this for a bit so I figure this might be useful to someone.
Git will not automatically update your local repository's default branch if the remote's default branch changes. So, if you change your default branch from master
to develop
, any copies of the repo cloned prior to the change will think master
is the default branch, while any copies after the change will think develop
is the default branch. This can cause the script to offer differing results depending on the machine you're on.
Solution: git remote set-head origin -a
will update the branch that git considers the origin/HEAD
to match the current default branch in the origin
remote.
Source: Stack Overflow
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.