Skip to content

Instantly share code, notes, and snippets.

@yhauxell
Created March 15, 2022 13:04
Show Gist options
  • Save yhauxell/2a9d677aa2e47edebb59da6e5862f970 to your computer and use it in GitHub Desktop.
Save yhauxell/2a9d677aa2e47edebb59da6e5862f970 to your computer and use it in GitHub Desktop.
function gitsync(){
CURRENT=$(git branch --show-current)
if [ -n "$1" ]
then
echo "Fetching branch $1"
git fetch origin $1:$1
echo "Merging $1 into $CURRENT"
git merge $1 -m "Merged branch $1 into $CURRENT"
echo "Pushing changes"
git push
git checkout $CURRENT
else
echo "Missing branch name to sync from"
fi
}
alias sync=gitsync
@yhauxell
Copy link
Author

Usage: add the function and alias to : .bash_profile or .zshrc

@yhauxell
Copy link
Author

yhauxell commented Mar 15, 2022

Then from the terminal in any part of a git project directory type for example to sync master branch: sync master

@yhauxell
Copy link
Author

yhauxell commented Sep 6, 2023

You can use rebase at line 10 if wanted to as well, depends on your strategy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment