Skip to content

Commit

Permalink
🔧 Add rebase bash script (#yoginth/eng-280)
Browse files Browse the repository at this point in the history
Summary: Added a bash script for rebasing feature branches with the main branch.

Highlights:

• Created `script/rebase` to automate rebasing and force-pushing.
• Includes checks for uncommitted changes and prevents rebasing on `main`.
• Handles fetching, rebasing, and force-pushing with error handling.

Read more: https://pierre.co/hey/hey/yoginth/eng-280
  • Loading branch information
Yoginth authored and Pierre committed Nov 13, 2024
1 parent fa41bea commit 7aa07f5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions script/rebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# Usage: script/rebase
# Rebase the current branch with the main branch and automatically force-push the changes

# Check for uncommitted changes
if [[ $(git status --porcelain) ]]; then
echo "Uncommitted changes detected. Please commit or stash them before running this script."
exit 1
fi

# Capture the current branch before switching
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" == "main" ]; then
echo "You are already on the main branch. Please switch to a feature branch to rebase."
exit 1
fi

# Fetch the latest changes from the remote repository
git fetch origin

# Check out the main branch and pull the latest changes
git checkout main
if ! git pull origin main; then
echo "Failed to pull the latest changes from main. Please check your network or remote repository."
exit 1
fi

# Switch back to the original branch
git checkout "$current_branch"

# Rebase the current branch onto the updated main branch
if ! git rebase main; then
echo "Rebase encountered conflicts. Please resolve them before proceeding."
exit 1
fi

echo "Rebase with main branch completed successfully."

# Force-push the rebased branch to the remote repository
if git push --force-with-lease; then
echo "Changes force-pushed to remote branch $current_branch successfully."
else
echo "Failed to force-push changes. Please check your remote branch status."
exit 1
fi

1 comment on commit 7aa07f5

@vercel
Copy link

@vercel vercel bot commented on 7aa07f5 Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./

web-heyxyz.vercel.app
web-git-main-heyxyz.vercel.app
heyxyz.vercel.app
hey.xyz

Please sign in to comment.