Skip to content

Instantly share code, notes, and snippets.

@adityadaniel
Created April 23, 2024 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityadaniel/372adba4d5aee3f817fb1f1870c98eff to your computer and use it in GitHub Desktop.
Save adityadaniel/372adba4d5aee3f817fb1f1870c98eff to your computer and use it in GitHub Desktop.
Sync current feature branch with latest changes from base branch
#!/bin/bash
function sync_base() {
parent=$(git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
current=$(git rev-parse --abbrev-ref HEAD)
echo "base $parent, current: $current"
echo "Switching to parent: $parent, make sure you already commit all your work"
git checkout $parent && git pull
echo "Switching to your current branch: $current"
git checkout $current
git merge $parent
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment