Skip to content

waskosky/bash-git-simplified

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bash Git Simplified

s 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 system bin (e.g., /usr/local/bin)
    ./install.sh symlink
    
    # Copy scripts to /usr/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
sudo cp scripts/git-* /usr/local/bin/

# Option 3: Create symlinks
sudo ln -s /path/to/bash-git-simplified/scripts/git-* /usr/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 prefers system-wide symlinks if the system bin is writable (with or without sudo).
  • If the system bin is unavailable or not writable, it installs to ~/.local/bin and adds it to your PATH.
  • 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
  • Automatically stashes uncommitted changes before pull
  • Restores stashed changes after successful pull
  • Handles merge conflicts gracefully

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 changes
  • 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)
  • 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
  • Automatically stashes uncommitted changes
  • 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

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
  • 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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages