Skip to content

Instantly share code, notes, and snippets.

@nahive
Created March 29, 2018 12:51
Show Gist options
  • Save nahive/60676a431d6cec99b068e94178e0f758 to your computer and use it in GitHub Desktop.
Save nahive/60676a431d6cec99b068e94178e0f758 to your computer and use it in GitHub Desktop.
Script for syncing current branch with other branch
#!/bin/bash
function sync {
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
echo -e "\033[0;32mSyncing branch $1 into branch $branch_name...\033[0m"
echo -e "$(git checkout $1 && git pull)"
echo -e "$(git checkout $branch_name && git merge $1)"
echo -e "\033[0;32mSuccess syncing $1 into branch $branch_name. You need to manage merge conflicts yourself."
}
if [ "$1" != "" ] ; then
sync $1
else
echo -e "\033[0;31mNeed to pass branch name to sync with. Usage: gitsync [branchname]."
fi
# you can add alias
# alias gitsync="source ~/.gitrc"
# then usage is gitsync develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment