Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# != 1 ]; then
  3. echo "usage: $0 <filename>"
  4. exit;
  5. fi
  6.  
  7. #fetch and track remote branches
  8. git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
  9.  
  10. branches=`git for-each-ref --format='%(refname:short)' refs/heads/\*`
  11. curr_branch=`git rev-parse --abbrev-ref HEAD`
  12.  
  13. filename=$1
  14. is_file_in_repo=`git ls-files ${filename}`
  15.  
  16. if [ ! "$is_file_in_repo" ]; then
  17. echo "file not added in current branch"
  18. exit
  19. fi
  20.  
  21. echo "Update $filename in each branch from $curr_branch"
  22. echo "Check that $filename isn't modified in the $curr_branch"
  23.  
  24. ##Bash >= version 3.2
  25. read -r -p "Are you sure? [y/N] " response
  26. if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
  27. then
  28. for branch in ${branches[@]}; do
  29. if [[ ${branch} != ${curr_branch} ]]; then
  30. echo "Updating $filename in $branch from $curr_branch"
  31. git checkout "${branch}"
  32. git checkout "${curr_branch}" -- "$filename"
  33. git commit -am "update $filename in $branch from $curr_branch"
  34. git push
  35. echo "-----------------------------"
  36. fi
  37. done
  38. git checkout "${curr_branch}"
  39. echo "Done"
  40. else
  41. echo "Bye"
  42. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement