DeveloperBreeze

Git Scripts Development Tutorials, Guides & Insights

Unlock 1+ expert-curated git scripts tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your git scripts skills on DeveloperBreeze.

Automating Git Workflows with Bash Scripts: Save Time and Avoid Mistakes

Tutorial August 20, 2024
bash

#!/bin/bash

# Check if branch name is provided
if [ -z "$1" ]; then
  echo "Please provide a branch name to merge into the current branch."
  exit 1
fi

# Fetch the latest changes
git fetch origin

# Checkout the current branch and merge
git checkout "$1"
git pull origin "$1"

# Merge the specified branch into the current branch
git checkout -
git merge "$1"

# Push the changes to the remote repository
git push

echo "Merged branch '$1' into the current branch and pushed changes."

Save this script as merge-branch.sh and run it with: