Git Extras

repository·main·Indexed 12 days ago

https://github.com/tj/git-extras

A collection of small, useful Git utilities that extend the standard Git CLI functionality. It provides tools for repository summaries, changelog management, workflow automation, and contribution metrics, including commands such as git-abort, git-authors, git-browse, git-bulk, and git-changelog.

Tokens
71.3K
Snippets
355
Records
405
Agent score
95%

What's inside Git Extras

  1. Overview of Git Extras utilities

    main

    Git Extras provides a collection of Git utilities designed to enhance your workflow. Key capabilities include:

    • Repository Summaries: Get high-level overviews of your repo.
    • REPL: Interactive command-line environments.
    • Changelog Population: Automate the creation of changelogs.
    • Author Commit Percentages: Analyze contribution metrics.
    • Workflow Automation: Commands like git-ignore, git-setup, git-changelog, git-release, and git-effort.
  2. Use git-standup to recall commit history

    main

    The git-standup command allows you to quickly see what commits were made recently. It can be used to review your own work from the last working day or to see the activity of other authors. If run from a directory that is not a git repository, it will automatically search for and aggregate data from all top-level git repositories found in the current directory tree.

    git standup
  3. Show effort statistics with git-effort

    main

    The git-effort command displays statistics about the effort put into files within a repository. It provides a list of files along with the number of commits per file and the total number of active days (days where modifications were contributed to that file). The output is automatically sorted by activity.

    Output columns:

    • file: The path to the file or directory.
    • commits: The number of commits touching the file.
    • active days: The total number of unique days that contributed modifications to the file.
    git effort
  4. Use git-ignore to manage .gitignore files

    main

    The git-ignore command allows you to modify or display .gitignore files across three different contexts: local (the project's .gitignore), global (the user's $HOME/.gitignore), and private (the repository's .git/info/exclude).

    Default Behaviors

    • No arguments: Prints the contents of all three contexts (global, local, and private).
    • Patterns only: Appends the provided patterns to the local .gitignore.
    • Action without context: Performs the action on the local .gitignore.
    • Context without action: Prints the contents of the selected context.

    Contexts

    FlagLong FlagDescription
    -l--localThe .gitignore file in the current working directory (default).
    -g--globalThe global gitignore file for the current user.
    -p--privateThe private exclude file for the repository (.git/info/exclude).
    git-ignore [<context>] [<action>] [--] [<pattern> [<pattern>]...]
  5. Use the --merge option with git-pr

    main

    The -m or --merge option allows you to check out a merge commit against the branch the pull request is targeting, rather than just the head of the PR branch.

    Important Note: This feature relies on a private GitHub API to check mergeability. It only works with opened pull requests. If the merge commit is not up-to-date, you must visit the pull request web page on GitHub to trigger a rebuild.

    # Checkout a merge commit for PR 755 from origin
    git pr origin:755 --merge
  6. Rewrite history with git-reauthor

    main

    The git reauthor command allows you to replace author and/or committer identities in commits and tags across all local branches. It preserves other metadata like dates and messages.

    WARNING: This command rewrites Git history. After running it, you will be unable to push your branches to a remote repository without using a force push (git push --force).

  7. Replace existing stamps with --replace

    main

    Use the --replace (or -r) flag to modify existing stamps in the last commit. When this flag is used, the command will first find and remove all previous stamps in the commit message that share the same identifier (case-insensitive) before appending the new one.

    This is useful for updating issue references or review links without creating a long list of redundant stamps.

    git stamp --replace <id> <message>
  8. Create a pull request for a GitHub project using git-pull-request

    main

    The git-pull-request command allows you to create a pull request for a GitHub project directly from the command line.

    When running the command, you will be prompted to provide a title, body, and the base branch. If you have two-factor authentication enabled on GitHub, you will also be prompted for your authentication code.

    Usage: git pull-request [<branch>]

    If you specify a <branch>, that local branch will be pushed and used as the pull request head. If no branch is specified, the command will prompt you for the head branch.

    $ git pull-request master
  9. Configure GitHub personal access token for git-pull-request

    main

    To use git-pull-request, you must provide a GitHub personal access token with the appropriate OAuth scopes for your repositories. You can provide this token using one of the following three methods:

    1. Environment Variable: Set the GITHUB_TOKEN environment variable.
    2. Global Git Config: Add the token to your global git configuration: git config --global --add git-extras.github-personal-access-token <your-personal-access-token>
    3. Local Repository Config: If you use multiple GitHub accounts, override the global setting within a specific repository: git config git-extras.github-personal-access-token <other-acc-personal-access-token>
    # Set globally
    git config --global --add git-extras.github-personal-access-token <your-personal-access-token>
    
    # Set for a specific repository (useful for multiple accounts)
    git config git-extras.github-personal-access-token <other-acc-personal-access-token>
  10. Check out a GitHub pull request locally with git-pr

    main

    The git pr command creates a local branch based on a GitHub pull request number or URL and automatically switches to that branch.

    Usage Patterns

    • By PR number: Uses the default remote (origin).
    • By PR number and remote: Specify a different remote (e.g., upstream).
    • By remote and number: Use the <remote>:number syntax.
    • By URL: Provide the full GitHub pull request URL.
    • Multiple PRs: You can pass multiple identifiers or URLs in a single command. If one fails, the command continues with the others, and the final exit code is determined by the last pull attempt.

    Cleaning up

    Use git pr clean to delete local branches that were created for pull requests.

    # Check out PR 226 from origin
    git pr 226
    
    # Check out PR 226 from upstream
    git pr 226 upstream
    
    # Check out PR 226 using remote:number syntax
    git pr upstream:226
    
    # Check out a PR using its GitHub URL
    git pr https://github.com/tj/git-extras/pull/453
    
    # Clean up old local PR branches
    git pr clean
  11. Use git-stamp to amend the last commit message

    main

    The git stamp command allows you to amend the most recent commit by appending a stamp message (an identifier followed by a message or URL). By default, stamps are appended as a new paragraph to the existing commit message.

    Warning: If a commit message already contains a line starting with the same identifier (even if it wasn't created by git stamp), the command will treat it as an existing stamp.

    git stamp <id> [<messages>]
  12. Continue a current git operation with git-continue

    main

    Use the git-continue command to resume a git operation that has been interrupted, such as a revert, rebase, merge, or cherry-pick. This is useful when a conflict occurs and you want to proceed with the operation after resolving it.

    Note that git-continue does not accept any options; it simply attempts to continue the ongoing process.

    git-continue