Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# != 1 ]; then
- echo "usage: $0 <filename>"
- exit;
- fi
- #fetch and track remote branches
- git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
- branches=`git for-each-ref --format='%(refname:short)' refs/heads/\*`
- curr_branch=`git rev-parse --abbrev-ref HEAD`
- filename=$1
- is_file_in_repo=`git ls-files ${filename}`
- if [ ! "$is_file_in_repo" ]; then
- echo "file not added in current branch"
- exit
- fi
- echo "Update $filename in each branch from $curr_branch"
- echo "Check that $filename isn't modified in the $curr_branch"
- ##Bash >= version 3.2
- read -r -p "Are you sure? [y/N] " response
- if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
- then
- for branch in ${branches[@]}; do
- if [[ ${branch} != ${curr_branch} ]]; then
- echo "Updating $filename in $branch from $curr_branch"
- git checkout "${branch}"
- git checkout "${curr_branch}" -- "$filename"
- git commit -am "update $filename in $branch from $curr_branch"
- git push
- echo "-----------------------------"
- fi
- done
- git checkout "${curr_branch}"
- echo "Done"
- else
- echo "Bye"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement