Skip to content

waskosky/bash-git-simplified

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bash Git Simplified

A collection of linux shell scripts that simplify common git operations. Each script performs a commonly needed git function that typically requires multiple commands or complex options. Almost entirely coded by Github Copilot Agents and OpenAI's gpt-5-high, and scripts may take unsafe actions, use with great caution.

Installation

Automatic Installation

  1. Clone this repository:

    git clone https://github.com/waskosky/bash-git-simplified.git
    cd bash-git-simplified
  2. Run the installation script:

    # Auto-detect/update (recommended). Re-run anytime to update.
    ./install.sh
    
    # Or explicitly choose a method:
    # Create symlinks in ~/.local/bin
    ./install.sh symlink
    
    # Copy scripts to ~/.local/bin
    ./install.sh copy
    
    # Add scripts directory to PATH
    ./install.sh path
  3. Reload your shell (for PATH method):

    source ~/.bashrc

Manual Installation

Alternatively, you can manually add the scripts to your PATH:

# Option 1: Add to your ~/.bashrc or ~/.zshrc
export PATH="$PATH:/path/to/bash-git-simplified/scripts"

# Option 2: Copy scripts to a directory already in PATH
mkdir -p "$HOME/.local/bin"
cp scripts/git-* "$HOME/.local/bin/"

# Option 3: Create symlinks
mkdir -p "$HOME/.local/bin"
ln -s /path/to/bash-git-simplified/scripts/git-* "$HOME/.local/bin/"

Updating

Just re-run ./install.sh with no arguments. It auto-detects your previous method and updates accordingly. For the symlink method, it also prunes stale symlinks that pointed to this repo.

Cross‑Linux Support

  • The installer works on any modern Linux distro with Bash and Git.
  • In auto mode, it installs user-local symlinks in ~/.local/bin and adds that directory to your PATH if needed.
  • The installer never invokes sudo. For a system-wide install, run as a user that can write the destination and set BASH_GIT_SIMPLIFIED_DEST_DIR=/usr/local/bin.
  • No distro-specific tools are required.

Uninstallation

To remove the scripts:

./uninstall.sh

Scripts

git-pull-latest

Pull and auto-merge the latest code from origin, with automatic stashing of uncommitted changes.

Usage: git-pull-latest [branch_name]

  • If no branch specified, uses current branch
  • Verifies origin/<branch> exists before stashing local work
  • Automatically stashes tracked and untracked changes before pull
  • Restores only the auto-stash it created, and keeps it with recovery commands if restore conflicts
  • Prints next actions when the remote branch does not exist

Example:

git-pull-latest          # Pull latest changes for current branch
git-pull-latest main     # Pull latest changes for main branch

git-reset-to-branch

Reset current branch to match another branch (useful for discarding local changes).

Usage: git-reset-to-branch [target_branch]

  • If no branch specified, resets to main (or master if main doesn't exist)
  • Warns before destroying uncommitted or untracked changes
  • Suggests git-backup-work before destructive reset
  • Cleans untracked files automatically
  • Fetches latest changes before reset

Example:

git-reset-to-branch      # Reset current branch to main
git-reset-to-branch dev  # Reset current branch to match dev

git-clean-start

Reset to a completely clean state, removing all uncommitted changes and untracked files.

Usage: git-clean-start [branch_name]

  • Removes ALL uncommitted changes and untracked files
  • Clears git stash
  • Resets to latest remote state
  • Requires confirmation before proceeding

Example:

git-clean-start          # Clean reset current branch
git-clean-start main     # Clean reset to main branch

git-reset-wipe

Hard reset the working tree to the last commit and remove untracked files.

Usage: git-reset-wipe [--yes]

  • Discards all uncommitted changes (git reset --hard HEAD)
  • Removes untracked files and directories (git clean -fd)
  • Keeps ignored files (use git-clean-start to remove ignored files too)
  • Prompts for confirmation unless --yes is provided

Example:

git-reset-wipe          # Prompt, then wipe to HEAD
git-reset-wipe --yes    # Skip prompt

git-safe-push

Safely commit all changes and push to origin with conflict resolution.

Usage: git-safe-push [commit_message]

  • Prompts for commit message if not provided
  • Shows changes before committing
  • Pulls latest changes before pushing (with rebase)
  • Creates missing origin branches with git push -u
  • Handles push conflicts automatically

Example:

git-safe-push "Fix bug in user authentication"
git-safe-push           # Will prompt for commit message

git-new-branch

Create and switch to a new branch from specified source branch.

Usage: git-new-branch <branch_name> [source_branch]

  • Creates new branch from source (default: current branch)
  • Switches to new branch automatically
  • Carries uncommitted changes to new branch
  • Fetches latest changes before creating branch

Example:

git-new-branch feature/user-login        # Create from current branch
git-new-branch hotfix/bug-fix main       # Create from main branch

git-backup-work

Create a backup branch of current work with timestamp.

Usage: git-backup-work [backup_suffix]

  • Creates timestamped backup branch
  • Includes all uncommitted changes and untracked files
  • Returns to original branch after backup
  • Optional suffix for custom naming

Example:

git-backup-work                    # Creates branch-backup-20240905-143022
git-backup-work before-refactor    # Creates branch-backup-20240905-143022-before-refactor

git-undo-commit

Safely undo the last commit while optionally preserving changes.

Usage: git-undo-commit [--hard]

  • Default: keeps changes in working directory (soft reset)
  • --hard: removes changes completely
  • Warns if commit was already pushed
  • Cannot undo initial commit

Example:

git-undo-commit         # Undo last commit, keep changes staged
git-undo-commit --hard  # Undo last commit, remove changes completely

git-sync-upstream

Sync with upstream repository (useful for forks).

Usage: git-sync-upstream [upstream_remote] [branch]

  • Default upstream remote: upstream
  • Default branch: main
  • Verifies the upstream branch exists before stashing local work
  • Automatically stashes tracked and untracked changes
  • Restores only the auto-stash it created, and keeps it with recovery commands if restore conflicts
  • Pushes updated branch to origin
  • Returns to original branch

Example:

git-sync-upstream                    # Sync with upstream/main
git-sync-upstream origin dev         # Sync with origin/dev
git-sync-upstream upstream master    # Sync with upstream/master

git-doctor

Show repository state and Git settings that commonly explain confusing tool output.

Usage: git-doctor

  • Shows current branch, upstream, commit, remotes, divergence, working tree changes, and stashes
  • Shows WSL/Desktop-sensitive settings including core.filemode, core.autocrlf, core.eol, and core.ignorecase
  • Warns when the repository is on a Windows-mounted WSL path
  • Suggests follow-up checks for GUI/terminal status disagreements

Example:

git-doctor

Features

  • Error Handling: All scripts include comprehensive error checking
  • Safety First: Scripts warn before destructive operations
  • Colored Output: Clear status messages with color coding
  • Interactive Prompts: Confirmation prompts for dangerous operations
  • Automatic Stashing: Preserves work when needed
  • Exact Stash Recovery: Auto-stash restore never blindly pops an older stash
  • Diagnostics: git-doctor explains branch, stash, dirty tree, and cross-platform settings
  • Conflict Resolution: Handles common git conflicts automatically

Requirements

  • Linux (any recent distro)
  • Git installed and configured
  • Bash shell

Contributing

Feel free to submit issues, feature requests, or pull requests to improve these scripts.

License

This project is open source. Feel free to use, modify, and distribute these scripts.

About

Simplified Git Scripts

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages