npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-squash-branch

v1.4.0

Published

Squash commits in a Git branch or pull-request

Downloads

18

Readme

git-squash-branch

Script to squash commits in a Git branch or pull-request.

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

Why?

To consolidate the commits in a branch to a single commit for a cleaner Git history.

Examples:

  1. Squashing WIP commits in the default branch of a new repository. I personally do this often when starting a new project.

  2. Squashing your PR's commits when squash merging is disabled on the repository you're contributing to.

  3. Squashing your PR's commits when your PR is deployed through another PR (e.g. in a batched PRs, GitHub cannot squash individual PRs in the batch)

Usage

Squash current branch

Run the script with npx from the repository branch you want to squash:

npx git-squash-branch

Example: squashing new commits in current branch compared to base branch

# You must be inside the branch you want to squash
$ git checkout branch-to-squash

$ npx git-squash-branch --base develop --message "feat: my new feature"

Successfully squashed with message:
feat: my new feature

To revert back to the original commit:
git reset --hard 4f0432ffd1

# Force push the squashed branch to remote
$ git push --force

Example: squashing all commits in current branch

$ git checkout main

$ npx git-squash-branch --base main --message "feat: init"

Current branch is the same as base branch. Squashing all commits to root.
Successfully squashed with message:
feat: init

To revert back to the original commit:
git reset --hard 4f0432ffd1

# Force push the squashed branch to remote
$ git push --force

Squash PR

⚠️ Requires GitHub CLI to be installed

From inside the repository directory, pass in the PR number, URL, or branch:

npx git-squash-branch pr [<number> | <url> | <branch>]

It will squash the PR branch into a single commit and force push it back to the PR branch.

Example

# You must be inside the repository for gh to fetch the PR
$ cd my-repo

$ npx git-squash-branch pr 1234

✔ Successfully squashed PR 1234 with message:
feat: my PR title

To revert the PR back to the original commit:
git push -f origin 4f0432ffd1:pr-branch-name

Note: This command will not update the PR with the latest base branch.

Manual

Usage:
  git-squash-branch [flags...]
  git-squash-branch <command>

Commands:
  pr

Flags:
  -b, --base <string>
  Base branch to compare against. If not specified, will try to
  detect it from remote "origin".

  -h, --help
  Show help

  -m, --message <string>
  Message for the squash commit (defaults to last commit message)

  -r, --remote <string>
  Remote to fetch from (default: "origin")

  --version
  Show version

What does this script do?

Basically runs these commands, derived from this StackOverflow answer:

$ git reset --soft $(git merge-base <base-branch> $(git branch --show-current))
$ git commit -m <message>

On top of that, it adds extra features such as:

  • Tries to automatically detect the base branch based on the origin remote
  • Defaults to using the commit message from the last commit, if not provided
  • Logs the current commit hash in case you want to revert the squash