Skip to content

A simple and fast development workflow that eliminates the need to manually create branches and pull requests. Just push to main, and let automation handle the rest.

Notifications You must be signed in to change notification settings

tarasowski/push

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

You can create a script to automate this workflow and integrate it into your main development process. Below is a shell script (push.sh) that implements the described setup. It requires the GitHub CLI (gh) and assumes you are comfortable with shell scripting and basic Git operations.

Script: push.sh

#!/bin/bash

# Exit on error
set -e

# Function to display usage
usage() {
    echo "Usage: $0 \"Pull Request Title (with optional #issue reference)\""
    exit 1
}

# Check if a title was provided
if [ -z "$1" ]; then
    usage
fi

# Variables
PR_TITLE="$1"                                   # Pull Request title from argument
BRANCH_NAME="temp-branch-$(date +%s)"          # Unique branch name with timestamp
MAIN_BRANCH="main"                             # Main branch name
REMOTE="origin"                                # Remote name (default is 'origin')

# Step 1: Create and checkout a new branch
git checkout -b "$BRANCH_NAME"

# Step 2: Add all changes and commit
git add .
if git diff-index --quiet HEAD --; then
    echo "No changes to commit."
    exit 0
fi
git commit -m "$PR_TITLE"

# Step 3: Push the new branch to GitHub
git push "$REMOTE" "$BRANCH_NAME"

# Step 4: Open a Pull Request using GitHub CLI
gh pr create --base "$MAIN_BRANCH" --title "$PR_TITLE" --body "Automated PR: $PR_TITLE"

# Step 5: Merge the Pull Request (requires GitHub CLI)
gh pr merge --auto --delete-branch

# Step 6: Cleanup local branch
git checkout "$MAIN_BRANCH"
git branch -d "$BRANCH_NAME"

# Done
echo "Pull request created, merged, and cleaned up successfully!"

How to Integrate This Script

  1. Save the Script
    Save the script above to a file, e.g., push.sh. Make it executable:

    chmod +x push.sh
  2. Install Dependencies

  3. Set Up Your Git Repository
    Ensure you have a Git repository with the main branch set up. You should also have permissions to push to and manage branches.

  4. Usage
    When you're ready to push changes, use the script like this:

    ./push.sh "Fixes #123: Correct login logic and improve performance"
    • This will:
      • Create a branch.
      • Commit all staged changes with the specified message.
      • Push the branch to GitHub.
      • Create a PR with the title.
      • Automatically merge the PR and clean up the branch.
  5. Optional Integration

    • Add the script to your PATH for easy use from anywhere:
      mv push.sh /usr/local/bin/push
    • Now, you can run push from any Git repository:
      push "Closes #456: Implement caching for API responses"

Key Points for Your Workflow

  • Script Customization:
    Adjust the branch naming convention or add more options if needed, such as setting a PR description.

  • Release Notes:
    With this setup, every PR title will become part of your commit history, and tools like GitHub’s release note generator will automatically use them.

  • Handling Merge Conflicts:
    If a merge conflict occurs during gh pr merge, you will need to resolve it manually.

  • Working Off main:
    This script aligns with your strategy of minimizing branch management while still leveraging PRs for tracking and linking to issues.

Let me know if you need further help refining or expanding this script!

About

A simple and fast development workflow that eliminates the need to manually create branches and pull requests. Just push to main, and let automation handle the rest.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages