Guest User

Untitled

a guest
Feb 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. . git-simple-common.sh
  4.  
  5. if [ X"$1" = X"-h" ]; then
  6. echo "Usage: git sync [branch]"
  7. echo " Synchronizes [branch] with its published counterpart, or if [branch] is not"
  8. echo " supplied, assumes your current branch."
  9. exit 0
  10. fi
  11.  
  12. BRANCH=$1
  13. [ -z ${BRANCH} ] && BRANCH=`current_branch_name`
  14.  
  15. FOUND_REMOTE_BRANCH=0
  16. for br in `remote_branch_names`; do
  17. branch=`echo $br | sed -e s,.*/,,g`
  18. [ X"$branch" = X"$BRANCH" ] && FOUND_REMOTE_BRANCH=1
  19. done
  20.  
  21. [ ${FOUND_REMOTE_BRANCH} -eq 0 ] && die "Could not find a published branch named '${BRANCH}'. Maybe publish first?"
  22.  
  23. stash_it "synching branches"
  24.  
  25. git fetch origin
  26.  
  27. REMOTE_NAME=`git remote`
  28.  
  29. MERGES=`git log --merges ${REMOTE_NAME}/${BRANCH}..${BRANCH} | grep commit`
  30. if [[ -n ${MERGES} ]]; then
  31. git merge ${REMOTE_NAME}/${BRANCH}
  32. else
  33. git rebase ${REMOTE_NAME}/${BRANCH}
  34. fi
  35.  
  36. git push ${REMOTE_NAME} ${BRANCH}
Add Comment
Please, Sign In to add comment