Last active
January 12, 2017 17:08
-
-
Save kevin-lee/5de308944b1f09443ac9 to your computer and use it in GitHub Desktop.
Git pull from multiple remote git repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright 2015 Lee, Seong Hyun (Kevin) | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gitpullall() | |
{ | |
repos_to_ignore="origin" | |
should_ignore=-1 | |
echo "running: git pull" | |
git pull | |
echo "" | |
for remote in `git remote` | |
do | |
echo "==================================" | |
echo "Remote: $remote" | |
echo "----------------------------------" | |
for ignore in $repos_to_ignore | |
do | |
[ "$remote" == "$ignore" ] && { should_ignore=1; break; } || : | |
done | |
if [ "$should_ignore" == "-1" ] | |
then | |
THIS_BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` | |
git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME$" 2>&1 > /dev/null || git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME""[[:space:]]\+" 2>&1 > /dev/null || { | |
echo "No info of the remote repo named '$remote' is found." | |
echo "So $remote will be fetched." | |
echo "running: git fetch $remote" | |
git fetch "$remote" | |
echo "" | |
} | |
if git branch -r | grep -sw "$remote/$THIS_BRANCH_NAME" 2>&1 > /dev/null ; then | |
echo "running: git pull $remote $THIS_BRANCH_NAME" | |
git pull "$remote" "$THIS_BRANCH_NAME" | |
else | |
echo "$THIS_BRANCH_NAME branch does not exist on the remote called '$remote'." | |
echo "So $remote will not be pulled from $remote." | |
fi | |
else | |
echo "$remote is on the ignored list so ignore it." | |
echo "Ignored: $remote" | |
fi | |
should_ignore=-1 | |
echo "==================================" | |
echo "" | |
done | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gitpullall() | |
{ | |
repos_to_ignore="origin" | |
should_ignore=-1 | |
echo "running: git pull" | |
git pull | |
echo "" | |
for remote in `git remote` | |
do | |
echo "==================================" | |
echo "Remote: $remote" | |
echo "----------------------------------" | |
for ignore in $repos_to_ignore | |
do | |
[ "$remote" = "$ignore" ] && { should_ignore=1; break; } || : | |
done | |
if [ "$should_ignore" = "-1" ] | |
then | |
THIS_BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` | |
{ git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME$" 2>&1 > /dev/null } || { git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME""[[:space:]]\+" 2>&1 > /dev/null } || { | |
echo "No info of the remote repo named '$remote' is found." | |
echo "So $remote will be fetched." | |
echo "running: git fetch $remote" | |
git fetch "$remote" | |
echo "" | |
} | |
if git branch -r | grep -sw "$remote/$THIS_BRANCH_NAME" 2>&1 > /dev/null ; then | |
echo "running: git pull $remote $THIS_BRANCH_NAME" | |
git pull "$remote" "$THIS_BRANCH_NAME" | |
else | |
echo "$THIS_BRANCH_NAME branch does not exist on the remote called '$remote'." | |
echo "So $remote will not be pulled from $remote." | |
fi | |
else | |
echo "$remote is on the ignored list so ignore it." | |
echo "Ignored: $remote" | |
fi | |
should_ignore=-1 | |
echo "==================================" | |
echo "" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add
gitpullall()
function to~/.bashrc
(or~/.bash_aliases
) for bash and~/.zshrc
for zsh.e.g.) add the information of gihub, gitlab and bitbucket remote repositories to your local git repository.
then run